unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}uses shlobj, ActiveX, ComObj;function ExeFromLink(const linkname: string): string;var link: IShellLink; storage: IPersistFile; filedata: TWin32FindData; buf: array[0..MAX_PATH] of Char; widepath: WideString;begin OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink, link)); OleCheck(link.QueryInterface(IPersistFile, storage)); widepath := linkname; Result := 'unable to resolve link'; if Succeeded(storage.Load(@widepath[1], STGM_READ)) then if Succeeded(link.Resolve(GetActiveWindow, SLR_NOUPDATE)) then if Succeeded(link.GetPath(buf, sizeof(buf), filedata, SLGP_UNCPRIORITY)) then Result := buf; storage := nil; link := nil;end;procedure TForm1.FormCreate(Sender: TObject);begin Caption:=ExeFromLink('D:\Administrator\Desktop\Project1.lnk');end;end.
附件列表