这是哈巴狗的代码
function tform1.GetSpecialFolder: string;
var
; Pidl: PItemIDList;
; handle : THandle;
; Comp: TComponent;
; LinkDir : string;
begin
; // Get the folder location (as a PItemIDList)
; result:='';
; Comp := self.owner;
; handle := (Comp as TForm).handle;
; if SUCCEEDED(SHGetSpecialFolderLocation(handle, CSIDL_APPDATA, Pidl))
; ; ;then begin
; ; // Get the actual path of the desktop directory from the PItemIDList
; ; ; ;SetLength(LinkDir, MAX_PATH); // SHGetPathFromIDList assumes MAX_PATH buffer
; ; ; ;SHGetPathFromIDList(Pidl, PChar(LinkDir)); // Do it
; ; ; ;SetLength(LinkDir, StrLen(PChar(LinkDir)));
; ; ; ;result := LinkDir+'/Microsoft/Internet Explorer/Quick Launch/';
; end;
end;
再用shelllink得到IPersistFile.save(GetSpecialFolder+linkfilename);
function tform1.GetSpecialFolder: string;
var
; Pidl: PItemIDList;
; handle : THandle;
; Comp: TComponent;
; LinkDir : string;
begin
; // Get the folder location (as a PItemIDList)
; result:='';
; Comp := self.owner;
; handle := (Comp as TForm).handle;
; if SUCCEEDED(SHGetSpecialFolderLocation(handle, CSIDL_APPDATA, Pidl)) ;then begin
; ; //other placeid is ; ;CSIDL_DESKTOP,CSIDL_NETHOOD,CSIDL_PRINTHOOD,
//CSIDL_PROGRAMS,CSIDL_SENDTO,CSIDL_STARTMENU,CSIDL_STARTUP ; ;
; ; // Get the actual path of the desktop directory from the PItemIDList
; ; ; ;SetLength(LinkDir, MAX_PATH); // SHGetPathFromIDList assumes MAX_PATH buffer
; ; ; ;SHGetPathFromIDList(Pidl, PChar(LinkDir)); // Do it
; ; ; ;SetLength(LinkDir, StrLen(PChar(LinkDir)));
; ; ; ;result:=linkdir+'/';//if not CSIDL_APPDATA
; ; ; ;result := LinkDir+'/Microsoft/Internet Explorer/Quick Launch/';//if CSIDL_APPDATA
; end;
end;
你可以用getspecialfolder获得start menu或程序组的起始路径,用
SHGetSpecialFolderLocation(handle,
CSIDL_PROGRAMS或CSIDL_STARTMENU, Pidl)) ;
用procedure Writelnk;
var
; ShellObj: IUnknown;
; ShellLink: IShellLink;
; PFile: IPersistFile;
; WFileName: WideString;
begin
; ShellObj := CreateComObject(CLSID_ShellLink);
; ShellLink := ShellObj as IShellLink;
; PFile := ShellObj as IPersistFile;
//Set Link properties
//Parameters
; ShellLink.SetArguments(PChar( Arguments ));
//Description
; ShellLink.SetDescription(PChar( Description ));
//Hotkey
; ShellLink.SetHotKey(HotKey);
//Icon
; if IconFile <> '' then
; ; ShellLink.SetIconLocation(PChar( IconFile ), IconIndex);
//Shelllink target
; ShellLink.SetPath(PChar( Path ));
//ShowCommand
; case WindowState of
; ; wsNormal ; : ShellLink.SetShowCmd(SW_SHOWNORMAL);
; ; wsMinimized: ShellLink.SetShowCmd(SW_MINIMIZE);
; ; wsMaximized: ShellLink.SetShowCmd(SW_MAXIMIZE);
; end;
//Working Dir
; if WorkingDirectory = '' then
; ; WorkingDirectory := ExtractFilePath( Path );
; ShellLink.SetWorkingDirectory(PChar( WorkingDirectory ));
// Save
; ; WFileName :=GetSpecialFolder+LinkFileName;
; PFile.Save(PWChar(WFileName), False);
end;
如果要加入到某个程序组中,先用createdir(startmenupath+‘/yourgroupname’);创建组。