How To Run Multiple Batch Files When Windows Starts (but no user logged on)
Last week I had an urgent support call to attend to as an e-commerce site I'd developed for a customer had stopped taking payments. You can imagine I jumped on to it pretty sharpish.
The problem soon became apparent - the payment-processing terminal wasn't running. The server had been re-booted and, although Domino re-started as a Service, as expected, the payment terminal didn't. This is because I (stupidly) had put a shortcut to the program in the "All Users" Startup Folder and assumed it would load if ever the machine re-started for any reason.
It turns out programs in the Startup folder only launch if a user logs in. In this case nobody did and so they never launched. Seems so obvious. What was I thinking!
As a quick fix I had them log in to Windows. I then went about finding a way to have the terminal launch without them needing to log in.
Launching Programs When Windows Boots
It turns out it's not as easy as you might imagine to run a program when Windows starts but before a user logs in. The only solution I found was to create your very own Service.
The process of creating your own service to run a batch file is documented in this Microsoft Knowledge Base article.
However, it only allows you to run one BAT file and it has to be called AutoExNT.bat. Whereas, in my case I wanted to run two different BAT files. One for each payment terminal (one live and one for testing). It turns out you can do this by calling the two (or more I guess) batch files directly from inside the AutoExNT.bat file.
Here's what my AutoExNT.bat file looks like:
start C:\path\to\batch\1\launch.bat C:\path\to\batch\2\launch.bat
The first line tells the existing command prompt to launch a new instance and load the first batch file in it. The second line then goes on to run the other batch file. The result being two command prompts running the code in the relevant batch file. Et voila.
Don't forget to install the Service with the /interactive flag set to On if you want to see the prompts yourself when you log in. Oh, and to check the Service is set to Automatic.
Using the built-in task scheduler in Windows XP, you can define tasks that start when the computer boots up. Seems like an easier solution to me :-)
Jeroen.
Reply
I read about using task scheduler, but also read that tasks started this way are in some way time limited and could well stop after X hours.
Reply
Could you have also set an agent to run on server startup that calls the batch file?
Reply
Guess so.
Reply
The risk there is that the site is ready to take a payment before AgentMgr actually kicks off the job, or so I would assume. I think having the site prerequisite controls and services running prior to server start is a more bullet proof solution. AgentMgr, you may recall, runs things when it gets to them - - as close to the time you designate as possible.
Reply
I just use the Windows Task scheduler various server start up tasks and set for "When my computer starts."
Reply
Hi Jake,
Another way you could do it is to set a startup script (bat file) using the group policy editor (Start / run and type in 'gpedit.msc'). Once the group policy editor comes up look under 'Computer Configuration / Windows Settings / Scripts.
You can also set a 'shutdown' script, which I've used in the past to automatically shut down virtual machines and the domino server before windows shuts down (useful, for example, when the UPS initiates a windows shutdown).
Reply
There are a couple of programs available, that are able to create and register regular programs as services, such as AppToService or MakeService.
Always did it for me in the past. It gives you the power and convenience to run an manage apps just like any Windows service without having to tinker with Windows internals too much.
At least MakeService is free to use, if I remember right, whereas AppToService is Shareware.
Reply
It sounds like you're happy that the system was running with a logged in user before, so you could use an auto login (such as http://support.microsoft.com/kb/324737)
all depends on your security reqt's. A service is much better, though.
Reply