logo

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.

Comments

    • avatar
    • Jeroen Jacobs
    • Thu 18 Mar 2010 06:06 AM

    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.

      • avatar
      • Jake Howlett
      • Thu 18 Mar 2010 06:28 AM

      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.

    • avatar
    • Niel
    • Thu 18 Mar 2010 08:00 AM

    Could you have also set an agent to run on server startup that calls the batch file?

      • avatar
      • Jake Howlett
      • Thu 18 Mar 2010 08:13 AM

      Guess so.

    1. 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.

  1. I just use the Windows Task scheduler various server start up tasks and set for "When my computer starts."

    • avatar
    • Richard Hogan
    • Thu 18 Mar 2010 04:49 PM

    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).

  2. 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.

    • avatar
    • IanB
    • Mon 29 Mar 2010 07:55 AM

    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.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Thu 18 Mar 2010

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content