--- ---
It's easy enough to drag and drop your application to the Windows Startup group to make it run on Windows startup. But, if you wanted to do this from your program, at the end of your setup program for example, or if you wanted to make your program run just once the next time Windows start, following function might come in handy:
procedure RunOnStartup(sProgTitle, sCmdLine: string; bRunOnce: boolean); var sKey: string; reg : TRegIniFile; begin if bRunOnce then sKey := 'Once' else sKey := ''; reg := TRegIniFile.Create(''); reg.RootKey := HKEY_LOCAL_MACHINE; reg.WriteString( 'Software\Microsoft\Windows\CurrentVersion\Run' + sKey + #0, sProgTitle, sCmdLine ); reg.Free; end;
Usage:
Example:
RunOnStartup('Title of my program', 'MyProg.exe', False);