Run a command on Windows startup (not login!)
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: https://stackoverflow.com/q/5899978/93180
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.)
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"
To run the task with elevated permissions (Vista and later), add the parameter /RL HIGHEST
Use Group Policy to run a Computer Startup script - this will run when the machine starts up without needing someone to login