Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do you tell Windows to run a command on each system startup?

I have a large number of servers on which I will need to run a command on system startup that makes a non-persistent configuration change.

I can run the command either:

  • as an executable with multiple parameters
  • as a batch file that calls above executable with appropriate parameters

How do I instruct Windows to run my command on every boot, without any sort of login?

related: http://stackoverflow.com/q/5899978/93180

share|improve this question

3 Answers 3

up vote 6 down vote accepted

Define a startup script with your desired BAT file. Do this either via Local Computer Policy (for standalone machines) or via GPO (if in a domain.)

share|improve this answer
    
How do I programmatically merge my changes into the computer policy? Do I just create a new key under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup and put the appropriate entries there? –  MikeyB May 4 '11 at 19:15
    
You're generally not supposed to manually touch anything in GPOs, AFAIK. And scripting options for making specific changes to GPOs are fairly lacking, from what I recall. You can export, import, create/delete, and link GPOs from scripts, but I don't think you can make specific changes to specific GPOs (easily.) Anyway, that's a different question, and one probably better suited to StackOverflow. –  mfinni May 4 '11 at 19:31
    
Yeah, writing up my question now. I'll need to add an entry to the GPO as part of an installer. –  MikeyB May 4 '11 at 19:37
    
Actually, now that I know what to look for: nsis.sourceforge.net/LGP_Startup/Shutdown_Script –  MikeyB May 4 '11 at 19:45

Use Group Policy to run a Computer Startup script - this will run when the machine starts up without needing someone to login

share|improve this answer

If you need to set the startup script programatically, you can use Scheduled Tasks:

schtasks.exe /create /tn "Task Name" /ru SYSTEM /Sc ONSTART /tr "C:\command2run.cmd"

share|improve this answer
    
To run the task with elevated permissions (Vista and later), add the parameter "/RL HIGHEST". –  abstrask Sep 22 '13 at 8:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.