Yep, this is the code I use to insert my program into the
Startup folder - modify filename Prorem to suit and if not startup folder change
those other parameters around:
procedure TPRForm.SetStart;
var
MyObject: IUnknown;
MySLink: IShellLink;
MyPFile: IPersistFile;
FileName: string;
Directory: string;
WFileName: WideString;
MyReg: TRegIniFile;
begin
var
MyObject: IUnknown;
MySLink: IShellLink;
MyPFile: IPersistFile;
FileName: string;
Directory: string;
WFileName: WideString;
MyReg: TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
FileName := application.Exename;
with MySLink do begin
SetArguments('');
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(ExtractFilePath(FileName)));
end;
MyReg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
// Use the next line of code to put the shortcut on your desktop
Directory := MyReg.ReadString('Shell Folders', 'Startup', '');
WFileName := Directory + '\ProRem.lnk';
MyPFile.Save(PWChar(WFileName), False);
MyReg.Free;
end;
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
FileName := application.Exename;
with MySLink do begin
SetArguments('');
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(ExtractFilePath(FileName)));
end;
MyReg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
// Use the next line of code to put the shortcut on your desktop
Directory := MyReg.ReadString('Shell Folders', 'Startup', '');
WFileName := Directory + '\ProRem.lnk';
MyPFile.Save(PWChar(WFileName), False);
MyReg.Free;
end;