macrozhang:你的程序我还没空看
<a href="http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=140602">here</a>
function tform1.GetSpecialFolder: string;
var//special folder
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
//also CSIDL_STARTMENU,DESKTOP can be used
//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;
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’);创建组。