----------
//创建桌面快捷方式 //FileName := ParamStr(0);
procedure CreateShortcutToDesktop(ShortcutName,Description,FileName:string;AgainCreateFlag:Boolean=False);//AgainCreateFlag 再次创建
var
ShortcutStr:string;
FileExistsFlag:Boolean;
ShLink: IShellLink;
PFile: IPersistFile;
WFileName: WideString;
Reg: TRegIniFile;
ComObjShortcut: IUnknown;
function GetDesktopPath():string;
var
pitem:PITEMIDLIST;
Buffer:PChar;
begin
Buffer:=StrAlloc(1024);
shGetSpecialFolderLocation(0,CSIDL_DESKTOP,pitem);
shGetPathFromIDList(pitem,Buffer);
Result:= string(Buffer);
StrDispose(Buffer);
end;
begin
ShortcutStr:=GetDesktopPath+'\'+ShortcutName+'.lnk';//快捷方式
FileExistsFlag:=FileExists(ShortcutStr);//快捷方式是否存在
if (FileExistsFlag and AgainCreateFlag)
or ( not FileExistsFlag ) then
begin
try
Reg := TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer');
ComObjShortcut := CreateComObject(CLSID_ShellLink); //快捷方式的初始化
ShLink := ComObjShortcut as IShellLink;
PFile := ComObjShortcut as IPersistFile;
ShLink.SetPath(PChar(FileName));
ShLink.SetWorkingDirectory(PChar(ExtractFilePath(FileName)));
ShLink.SetDescription(PChar(Description));
WFileName := Reg.ReadString('Shell Folders', 'Desktop', '') + '\' + ShortcutName + '.lnk';
PFile.Save(PWChar(WFileName), False);
finally
Reg.Free;
end;
end;
end;
-----------------------
----------
//调用SysShortcutName 快捷方式的名字不需要路径,只是自定义的名字
CreateShortcutToDesktop(SysShortcutName,'Developer:'+SysDeveloper+#13#10+ ' Company:'+SysCompanyName+#13#10+' Version:'+SysVersion,ParamStr(0),True);
----------