delphi编程创建桌面快捷方式
uses ActiveX,ComObj,StdCtrls,ShlObj,FileCtrl;
procedure TForm1.N2Click(Sender: TObject);
var
tmpObject : IUnknown;
tmpSLink : IShellLink;
tmpPFile : IPersistFile;
PIDL : PItemIDList;
StartupDirectory : array[0..MAX_PATH] of Char;
StartupFilename : String;
LinkFilename : WideString;
begin
//创建快捷方式到桌面
StartupFilename :=Application.ExeName;
tmpObject := CreateComObject(CLSID_ShellLink);//创建建立快捷方式的外壳扩展
tmpSLink := tmpObject as IShellLink;//取得接口
tmpPFile := tmpObject as IPersistFile;//用来储存*.lnk文件的接口
tmpSLink.SetPath(pChar(StartupFilename));//设定所在路径
tmpSLink.SetWorkingDirectory(pChar(ExtractFilePath(StartupFilename)));//设定工作目录
SHGetSpecialFolderLocation(0,CSIDL_DESKTOPDIRECTORY,PIDL);//获得桌面的Itemidlist
tmpSLink.SetDescription(’我的程序的描述);
tmpSLink.SetIconLocation(Pchar(StartupFilename),0);
SHGetPathFromIDList(PIDL,StartupDirectory);//获得桌面路径
LinkFilename := StartupDirectory + ’我的程序.lnk’;
tmpPFile.Save(pWChar(LinkFilename),FALSE);//保存*.lnk文件
end;