Mega Code Archive

 
Categories / Delphi / Examples
 

How to get the Link Info

Title: How to get the Link Info Question: How to get the Link Info Answer: Please refer also to: How to display all AutoRun Information e.g. ShowMessage( GetLinkInfo(TForm1.Handle, 'C:\ {Folder to Autostart} \Norton AntiVirus AutoProtect.Ink' ) ); function GetLinkInfo(WinhWnd:HWND;LnkObj:string):String; var hres : HRESULT; psl : IShellLink; ppf : IPersistFile; wfd : Win32_Find_Data; Path : array[0..MAX_PATH] of Char; begin result := '????'; //initializes the Component Object Model(COM) library CoInitialize(nil); // Call CoCreateInstance to obtain the IShellLink Interface pointer. hres:=CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IID_IShellLinkA, psl); if NOT SUCCEEDED(hres) then exit; // The IShellLink Interface supports the IPersistFile // interface. Get an interface pointer to it. hres:=psl.QueryInterface(IID_IPersistFile,ppf); if SUCCEEDED(hres) then begin // Convert the given link name string to wide character string. // and Load the file. hres:=ppf.Load(StringToOLEStr(LnkObj),STGM_READ); if SUCCEEDED(hres) then begin // Resolve the link by calling the Resolve() interface function. hres:=psl.Resolve(WinhWnd,SLR_ANY_MATCH OR SLR_NO_UI); if SUCCEEDED(hres) then begin hres:=psl.GetPath(Path,MAX_PATH,wfd,SLGP_SHORTPATH); if SUCCEEDED(hres) then result:=Path; end; end; end; end;