uses ShlObj, ActiveX, ComObj, Registry;<br><br> ...........................<br><br> Procedure SetLink(FolderNo: Integer; ACmdFile, Parameter, LinkName: string);<br><br> const<br> Folder: array[0..2] of string = ("Desktop", "Start Menu", "Programs");<br> var<br><br> MyObject : Iunknown;<br> MySLink : IShellLink;<br> MyPFile : IPersistFile;<br> FileName : string;<br> Directory : string;<br> WFileName : WideString;<br> MyReg : TRegIniFile;<br><br> begin<br><br> MyObject := CreateComObject(CLSID_ShellLink);<br> MySLink := MyObject as IShellLink;<br> MyPFile := MyObject as IPersistFile;<br> FileName := ACmdFile;<br> with MySLink do<br>begin<br><br> SetArguments(Pchar(Parameter));<br> SetPath(Pchar(FileName));<br> SetWorkingDirectory(Pchar(ExtractFilePath(FileName)));<br> end;<br><br> MyReg := TRegIniFile.Create(<br> "Software/MicroSoft/Windows/CurrentVersion/Explorer");<br> if ((FolderNo $#@60; 0) or (FolderNo $#@62; 2)) then<br> FolderNo := 0;<br> Directory := MyReg.ReadString("Shell Folders", Folder[FolderNo],"");<br> //CreateDir(Directory);<br> WFileName := Directory + "/" + LinkName + ".lnk";<br> MyPFile.Save(PWChar(WFileName),False);<br> MyReg.Free;<br> end;<br><br>例如:在桌面、开始菜单、程序菜单中添加计算器的快捷方式:<br><br> SetLink(0, "c:/windows/calc.exe", "", "计算器");<br> SetLink(1, "c:/windows/calc.exe", "", "计算器");<br> SetLink(2, "c:/windows/calc.exe", "", "计算器");<br><br>