1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69:
| unit ShellLink;
interface
uses Windows, SysUtils, Classes, Menus, ShlObj, CommCtrl, ComObj, ActiveX;
type TShellLinkInfo = record Error : Boolean; LinkName : string[255]; Description : string[225]; FileName : string[225]; WorkingDirectory : string[225]; Arguments : string[225]; WindowState : Integer; HotKey : TShortCut; IconFileName : string[225]; IconIndex : Integer; end;
function GetShellLinkInfo(LinkName: string): TShellLinkInfo;
implementation
function GetShellLinkInfo(LinkName: string): TShellLinkInfo; var HRes: HResult; Link: IShellLink; PerFile: IPersistFile; Buffer: array[0..255] of Char; IntBuffer: Integer; WordBuffer: Word; Size: Integer; W: PWideChar; Data: TWin32FindData;
begin result.Error:=False;
Size:=(Length(LinkName)+1) * sizeof(WideChar); GetMem(W, Size); StringToWideChar(LinkName, W, Size);
HRes := CoInitialize(nil); HRes := CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink, Link); if not Succeeded(HRes) then result.Error:=True;
HRes:=Link.QueryInterface(IPersistFile, PerFile); if not Succeeded(HRes) then result.Error:=True;
HRes := PerFile.Load(W, STGM_READ); if not Succeeded(HRes) then result.Error:=True;
result.LinkName:=LinkName;
Link.GetPath(@Buffer, MAX_PATH-5, Data, SLGP_UNCPRIORITY); result.FileName := StrPas(Buffer);
Link.GetWorkingDirectory(@Buffer, MAX_PATH-5); result.WorkingDirectory := StrPas(Buffer);
CoUninitialize;
FreeMem(W, Size); end;
end. |