A few days ago, at the request of the customer, I actually used VB and VC to write this thing faster, but I still like to use DELPHI
First of all, use ActiveX, ComObj, StdCtrls, ShlObj, FileCtrl;
Create a shortcut to the current application in the specified folder
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;
// Get the path to the start group of Start->Program->
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 // Other special paths can also be used CSIDL_COMMON or, just check it in delphi
Begin
SetLength(LinkDir, MAX_PATH);
SHGetPathFromIDList(Pidl, PChar(LinkDir));
SetLength(LinkDir, StrLen(PChar(LinkDir)));
result:=linkdir+'/';
end;
end;
//Some of the content borrows from Monopoly BBS content