Version Info: Works with Delphi 3 and higher.
Category: Shell API
Description: Create a Windows ShellLink (.lnk) file with Delphi.
Many of the Windows API calls are provided as COM interfaces, including IShellLink. This interface can be used to create a link on the Windows desktop.
uses ááActiveX, ComObj, ShlObj;
const ááIID_IPersistFile: TGUID = (D1: $0000010B; D2: $0000; D3: $0000; D4:($C0, $00, $00, $00, $00, $00, $00, $46));
function CreateLink(aPathObj, aPathLink, aDesc: string): Boolean; var áásLink: IShellLink; ááPersFile: IPersistFile;
begin ááResult := False; ááif Succeeded(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IID_IShellLinkA, sLink)) then áábegin áááásLink.SetPath(PChar(sPathObj)); áááásLink.SetDescription(PChar(aDesc)); ááááif Succeeded(sLink.QueryInterface(IID_IPersistFile, PersFile)) then áááábegin ááááááPersFile.Save(StringToOleStr(aPathLink), True); ááááááResult := True; ááááend; ááend; end;
procedure TForm1.Button1Click(Sender: TObject); begin ááif not CreateLink('command.com', 'c:\temp\mylink.lnk', 'description...') then áábegin áááá// Error Handling ááend; end;
----------- Larry J. Rutledge
Programmer / Analyst Prestwood Software & Consulting 7525 Auburn Blvd., #8 Citrus Heights, CA 95610
Old UBB Archived Link: [URL=http://www.prestwood.com]www.prestwood.com[/URL]
Serving your IT needs since 1984!
[This message has been edited by Larry Rutledge (edited November 30, 2000).] Larry J. Rutledge
Analyst
Prestwood Software
www.prestwood.com
|