本文整理自网络,侵删。
uses shlobj,ActiveX,ComObj;
function TForm1.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.Button2Click(Sender: TObject);
begin
//edit3.text:='C:\Documents and Settings\hjh\桌面\OA客户端.lnk';
Edit4.Text:=ExeFromLink(edit3.Text);
//Edit4.text:='D:\Program Files\OA客户端\OAUpdate.exe';
end;
相关阅读 >>
Delphi三层开发小技巧:tclientdataset的delta妙用
更多相关阅读请进入《Delphi》频道 >>