前幾天應客戶要求寫這個東西,其實用VB,VC可能更快些,不過,我還是喜歡用Delphi
首先 uses ActiveX,ComObj,StdCtrls,ShlObj,FileCtrl;
在指定文件夾建立當前應用程序才的快捷方式
procedure Tform1.MakeLink(Foldername:string;proName, lnkName, Description: string);
var
WorkDir, DestName: string;
aObj: IUnknown;
MyLink: IShellLink;
MyPFile: IPersistFile;
WFileName: WideString;
curdir: array[0..100] of Char;
begin
DestName := Foldername + lnkName;
aObj := CreateComObject(CLSID_ShellLink);
MyLink := aObj as IShellLink;
MyPFile := aObj as IPersistFile;
GetCurrentDirectory(sizeof(curdir), curdir);
workdir := curdir;
proname := trim(WorkDir)+''+proname;
with MyLink do
begin
SetShowCmd(SW_NORMAL);
SetArguments('');
SetDescription(pChar(Description));
SetPath(pChar(proName));
SetWorkingDirectory(pChar(WorkDir));
end;
CreateDir(ExtractFilePath(DestName));
WFileName := DestName;
MyPFile.Save(PWChar(WFileName), False);
end;
//獲得開始->程序->的啟動組 的路徑
function Tform1.GetSpecialFolder: string;//get starup Floder
var
Pidl: PItemIDList;
handle : THandle;
Comp: TComponent;
LinkDir : string;
begin
result:='';
Comp := self;//self.owner;
handle := (Comp as TForm).handle;
if SUCCEEDED(SHGetSpecialFolderLocation(handle, CSIDL_COMMON_STARTUP, Pidl)) then //別的特殊路徑也可以用CSIDL_COMMON或的,在Delphi中查一下就可以了
begin
SetLength(LinkDir, MAX_PATH);
SHGetPathFromIDList(Pidl, PChar(LinkDir));
SetLength(LinkDir, StrLen(PChar(LinkDir)));
result:=linkdir+'';
end;
end;
//部分內容借鑒了大富翁bbs上的內容