Restarting my app at bootup

Everything else that doesn't fall into one of the other PB categories.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Restarting my app at bootup

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Restarting my app at bootup

Post 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)
GoodNPlenty
Enthusiast
Enthusiast
Posts: 112
Joined: Wed May 13, 2009 8:38 am
Location: Arizona, USA

Re: Restarting my app at bootup

Post 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.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Restarting my app at bootup

Post by MachineCode »

Thanks for all replies, I will check them out.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Restarting my app at bootup

Post 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 
BERESHEIT
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Restarting my app at bootup

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Post Reply