Monday, April 19, 2010

Running multiple applications concurrently from a batch script in Windows 7 or XP

The Problem


Let's assume your organization has a fully automated PC setup procedure but one legacy application requires you to copy and paste (or manually type) a serial number. You are setting up 1000 computers with this app and there's no work around yet. Huge waste of your time right?

What do you do? Well you could open a text file with the serial number before running the installer. This way you only have to perform copy/paste and don't have to go on your network drive to find the file each time. This should save you about a 30 seconds on each machine or 500 minutes total. Not bad for a simple little script. So how do we accomplish this?

The Old Solution


In Windows XP this can be accomplished by creating a Windows Shortcut to the text file and the application then calling our Shortcuts from the script as below:

"\\fileserver\My Folder\myinstaller.lnk"
"\\fileserver\My Folder\mytextfile.lnk"


Unfortunately, this doesn't work in Windows 7 or Vista. Why?

It has to do with how both OS's handle shortcuts. Previously XP would invoke the application from a Windows Shortcut wait for the return code. This allowed you to invoke as many applications from a shortcut as you wanted without ever having to wait for a return code. In the updated Windows 7 and Vista operating systems, when you invoke a shortcut the batch script actually waits for the application to return a return code before proceeding.

Ok, so using Windows Shortcuts isn't an option unless we're using only XP. So how else can we accomplish this?

The New Solution


Basically we're going to do this:

start "" "\\fileserver\Installers\MyApplication\setup.exe"
start "" "\\fileserver\My Folder\mytextfile.txt"


This works by invoking the using the start command. The first parameter is two quotation marks and the second is the location of the program or document to run. Notice that we actually invoke the text document second in this case because we want it to appear on top so that you can copy the serial number, then close the document and have setup already running in the background.