Posted by bobp12404 on February 01, 2009
In Reply to Programmatically make program start on Windows start posted by Diane Channers P15844 on
January 31, 2009
: : : How can I make an Delphi application start every time that Windows starts?
: : Create a shortcut for your application and drag the shortcut (or copy and paste the shortcut) to
: : C:\Documents and Settings\YOUR_WINDOWS_USER_NAME\Start Menu\Programs\Startup
: Thanks for your swift answer, I already knew this myself ;)
: But I want to do this under program control, from within my Delphi application. For example, a Delphi app that asks "Autostart with Windows?" and if "yes" is clicked, it does all the necessary things. And vice versa, on clicking "no" the app should not anymore start at the next Windows startup.
: Is this possible? Thanks a lot in advance!
DelphiLand has you covered:
Click the "Code snips" link on the left hand side, then click the
"Launch application at Windows Startup: Run and RunOnce Registry keys" link (http://www.festra.com/eng/mtut07.htm)
Here is a short snippet, but more info is on that page:
procedure RunOnWinStart(ApTitle, ApPathFile: string; RunOnce: Boolean); var Reg: TRegistry; TheKey: string; begin Reg := TRegistry.Create; Reg.RootKey := HKEY_LOCAL_MACHINE; TheKey := 'Software\Microsoft\Windows\CurrentVersion\Run'; if RunOnce then TheKey := TheKey + 'Once'; // Open key, or create it if it doesn't exist Reg.OpenKey(TheKey, True); Reg.WriteString(ApTitle, ApPathFile); Reg.CloseKey; Reg.Free; end;
Lots of cool stuff there. :)