Page 1 of 1

Restarting my app at bootup

Posted: Sat Sep 10, 2011 4:55 am
by MachineCode
I know how to make my app start at bootup, no problem. But, this means the PC has to have a single user account with no password, otherwise my app can't run because no user is logged in when the PC boots. How to get around this problem? Note: The reason I need this, is because my PC rebooted by itself while I was out, and thus my app wasn't running anymore when I got home. I want to avoid this happening in future.

Re: Restarting my app at bootup

Posted: Sat Sep 10, 2011 7:35 am
by jesperbrannmark
Sound like you want to install your program executable as a service.
I have never tried this myself, but a quick google search gave me:
http://www.qweas.com/download/system/de ... ervice.htm
http://www.governmentsecurity.org/forum ... opic=11979
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /v ServiceName /d "c:\path\to\service\file\exe"
http://smallvoid.com/article/winnt-services-srvany.html
Instsrv.exe MyService C:\Srvany.exe

[HKEY_LOCAL_MACHINE \SYSTEM \CurrentControlSet \Services \MyService \Parameters]
Application = "C:\MyApp.exe"
(dont blame me if its crap programs, i havnt tried them)

Re: Restarting my app at bootup

Posted: Sat Sep 10, 2011 10:21 am
by GoodNPlenty
You might try using the Group Policy Editor to launch your app under Startup.

Click "Start" "Run" or "Search programs and files" then type gpedit.msc
In the console tree, click "Computer Configuration"->"Windows Settings"
Double click "Scripts(Startup/Shutdown)" then Double click "Startup" in right pane.
Click the "Add" button and browse to your program.
In Script Parameters, type any comand line arguments that you want and then click "Ok"
Click "Ok" again.
Exit out of all the Group Policy Editor.

Now when Windows boots your app will run for you before the user logs on.
Note: Your app will run under the Local System account, and have the full rights to run as Local System.

Re: Restarting my app at bootup

Posted: Sat Sep 10, 2011 12:33 pm
by MachineCode
Thanks for all replies, I will check them out.

Re: Restarting my app at bootup

Posted: Sat Sep 10, 2011 1:40 pm
by netmaestro
Here is some code from Joakim Christiansen. Note the comment for the first line of the procedure:

Code: Select all

Procedure StartWithWindows(State.b) 
  Protected Key.l = #HKEY_CURRENT_USER ;or #HKEY_LOCAL_MACHINE for every user on the machine 
  Protected Path.s = "Software\Microsoft\Windows\CurrentVersion\Run" ;or RunOnce if you just want to run it once 
  Protected Value.s = "GmailEnhancer" ;Change into the name of your program 
  Protected String.s = Chr(34)+ProgramFilename()+Chr(34) ;Path of your program 
  Protected CurKey.l 
  If State 
    RegCreateKey_(Key,@Path,@CurKey) 
    RegSetValueEx_(CurKey,@Value,0,#REG_SZ,@String,Len(String)) 
  Else 
    RegOpenKey_(Key,@Path,@CurKey) 
    RegDeleteValue_(CurKey,@Value) 
  EndIf 
  RegCloseKey_(CurKey) 
EndProcedure 

Re: Restarting my app at bootup

Posted: Sat Sep 10, 2011 2:44 pm
by MachineCode
Thanks, but Joakim's code doesn't work because no user is logged in after a reboot. Plus, only admins can set #HKEY_LOCAL_MACHINE, and my users may be under a limited account.