unit lnk;<br><br>interface<br>uses<br> Activex,<br> Comobj,<br> shlobj,<br> windows,<br> SysUtils;<br>type<br> PShellLink = ^TshellLink;<br> TShellLink = record<br> PathName, Arguments, Description, WorkingDirectory, IconLocation: string;<br> IconIndex: Integer;<br> ShowCmd: Integer;<br> HotKey: Word;<br> end;<br>function GetShellLink(const LinkFile: WideString): TShellLink;<br>procedure CreateLnk(sFileName, sLink: string; pchDes: LPSTR);<br><br><br>implementation<br><br>function GetShellLink(const LinkFile: WideString): TShellLink;<br>var<br> SL: IShellLink;<br> PF: IPersistFile;<br> FindData: TWin32FindData;<br> AStr: array[0..MAX_PATH] of char;<br>begin<br> OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,<br> IShellLink, SL));<br> PF := SL as IPersistFile;<br> OleCheck(PF.Load(PWideChar(LinkFile), STGM_READ));<br> OleCheck(SL.Resolve(0, SLR_ANY_MATCH or SLR_NO_UI));<br> with Result do<br> begin<br> OleCheck(SL.GetPath(AStr, MAX_PATH, FindData, SLGP_UNCPRIORITY));<br> PathName := AStr;<br> OleCheck(SL.GetArguments(AStr, MAX_PATH));<br> Arguments := AStr;<br> OleCheck(SL.GetDescription(AStr, MAX_PATH));<br> Description := AStr;<br> OleCheck(SL.GetWorkingDirectory(AStr, MAX_PATH));<br> WorkingDirectory := AStr;<br> OleCheck(SL.GetIconLocation(AStr, MAX_PATH, IconIndex));<br> IconLocation := AStr;<br> OleCheck(SL.GetShowCmd(ShowCmd));<br> OleCheck(SL.GetHotKey(HotKey));<br> end;<br>end;<br><br> { 建立Lnk档 }<br>procedure CreateLnk(sFileName, sLink: string; pchDes: LPSTR);<br>var<br> psl: IShellLink;<br> ppf: IPersistFile;<br> pchBuf: array[0..1024] of Char;<br> wch: array[0..1024] of WideChar;<br>begin<br> try<br> psl := CreateComObject(CLSID_ShellLink) as IShellLink;<br> try<br> ppf := psl as IPersistFile;<br> OleCheck(psl.SetDescription(pchDes));<br> StrPCopy(pchBuf, sFileName);<br> OleCheck(psl.SetPath(pchBuf)); StrPCopy(pchBuf, sLink);<br> MultiByteToWideChar(CP_ACP, 0, pchBuf, -1, wch, 1024);<br> OleCheck(ppf.Save(wch, True));<br> finally<br> ppf := nil;<br> end;<br> finally<br> psl := nil;<br> end;<br>end;<br><br>end.