Link to home
Start Free TrialLog in
Avatar of fsoehnge
fsoehnge

asked on

How do I run a command after the server reboots

I am needing to run a command automatically after a Windows 2003 server reboots. The reboot is being decided from within a batch file. I have tried adding the following line to my controlling script prior to the reboot.

soon 300 "cmd /c mycommand"

This goes into the AT commandline scheduler quite nicely. Unfortunately, after rebooting the server, the AT scheduler is empty. Any way to keep this from happening, or any ideas on another to automatically run my command upon completion of the reboot?
Avatar of Adam Brown
Adam Brown
Flag of United States of America image

Running scripts after startup usually requires putting the script into the Documents and Settings\All Users\Start Menu\Startup folder or adding the script to the Run section in the registry. http://www.windowsnetworking.com/kbase/WindowsTips/WindowsXP/AdminTips/Miscellaneous/WindowsProgramStartupLocations.html has info on that.
Avatar of fsoehnge
fsoehnge

ASKER

Any idea on why the AT schedule is getting cleared?
Havd you tried using scheduled tasks instead of the at scheduler?
I have not figured a way to use now + 5 minutes with the scheduled tasks. with the at command I am able to use soon 300 to schedule a task for 5 minutes from now. do you know how I can use scheduler from the command line to do the same thing?
Why not put the command you need to run in a batch file and set the task.to.run on reboot.  The batch file can then contain "soon" and effectively delay starting yhe program for 5 minutes.
So, if I have
c:\scripts\mycommand.bat

how do I set that task to run on reboot?
Go to Task Scheduler in the Administrative tools and create a new task.  The "trigger" option includes settings for:
Daily
Weekly
Monthly
One time
When the computer starts
When I log on
When a specific event is logged

The one I think you want is in bold.
I need to be able to do it from the command line.
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial