Boy I really miss Unix sometimes. Things that are so super easy in Unix/Linux are often a total pain in the butt in the Windows world.
I needed a script to gracefully shutdown and startup an application when the server was rebooted. Again, not an issue so much with linux as you almost never HAVE to reboot. Windows you reboot like you catch a cold. “oh you are not feeling well? Reboot twice and call me in the morning.” Plus windows systems like to reboot every time there is any sort of patching going on. So I needed to be able to have a custom script run to stop and start an application.
A startup script is a quick and easy way of getting a process running when the machine boots. The computer startup process will be affected by the time it takes to run the program, though, so you might want to ensure you call it with the START command from a batch file, or specifying not to wait for the executable to complete from whatever script language you use. (the key point there is: run the script asynchronously unless it’s critical, or doesn’t need to be run asynchronously cos it will always take no time at all. Long boots = unhappy users).
In Windows XP/2003 you will need to use the group policy editor which can be found under Start / Run / GPEDIT.MSC. You will then need to navigate to Computer Settings -> Windows Settings -> Scripts (Startup/Shutdown) or something similar to be able to set a startup script. You can see the scripts outlined in the scripts.ini file or add your own scripts to the Startup/Shutdown directories found under: C:\WINDOWS\System32\GroupPolicy\Machine\Scripts\
Using a Win32 Service is an alternative option – you can use the SRVANY utility from the Resource Kit to “service-ify” pretty much any executable. VS .Net and later also let you build a managed service directly.
And Task Scheduler gets much more capable as of Vista/2008, able to run scripts at startup, on idle, when certain other conditions are met; it’s pretty cool. Task scheduler has the possible advantage of being able to specify the user account under which the task runs, if that’s important to you.
I hope this little tid-but of information can be helpful to those that need this sort of thing.
