August 2008

Use Cmd.exe's Start Command to Simplify Setup Automation

Achieve small-scale software deployment without errors or omissions
RSS
Subscribe to Windows IT Pro | See More Windows OSs Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!
SideBar    Use Batch Files to Automate Application Installation

Many organizations are too small to cost-effectively deploy software by using tools such as Microsoft Systems Management Server (SMS). The person responsible for software installation—typically an external IT consultant or an employee with part-time support duties—falls back on manually installing each application on system rebuilds or new installations, which can be a slow and potentially error-prone process. However, by using a simple batch file and cmd.exe’s Start command, it’s possible to speed up the deployment process and reduce the risk of accidental omissions. Let’s look at when and why you’d want to use this method, then walk through how to deal with some of the problems you might encounter.

Why Start?
Cmd.exe’s Start command is a simple tool with features that make it ideal for basic setup automation. In general, any command you can run on a Windows system can be run from a batch file. You can add command-line options as necessary, and the batch file can wait for each command to finish before running the next command.

Why use Start? It’s easy to forget specific applications that you need to install for a system. For example, you might forget to install a small application even though it’s important to a client. At small sites that you rarely visit, you might get distracted by troubleshooting tasks in the middle of configuring a system and forget where you are in a chain of application installations. By wrapping all of the setup launchers into a batch file, there’s no danger of forgetting an application. If you don’t need to install a particular application in the set, you can always cancel its installation and go on to the next one.

It’s also easy to lose specific application sources that are on a network. Again, a batch file will have all of these locations in it, eliminating the headache of searching for those items.

Finally, even when you do know where everything is, you can waste a significant amount of time navigating to files and waiting for applications to start up and shut down. The Start command will shave off some of this start-up time. And when applications have installers that support command-line automation, installation can even proceed while you’re doing other work elsewhere. Let’s look at the proper way to run setups now.

Use the Wait Option
By default, the Start command always spawns an application in a new process and continues on its way. Obviously, it’s not a good idea to start up 17 different installers simultaneously; the resource demand would overload almost any PC. In any case, well-behaved Windows Installer (.msi)–based installation programs will refuse to run if another .msi-based installation is already running, making it easier for Windows to untangle applications. To handle this situation, simply include the /wait option with the Start command. You can abbreviate the /wait option to /w. To run the installer located at z:\dsp xp\WindowsXP-KB926139-x86-ENU.exe, you would start it like this:

start /w z:\dsp\xp\WindowsXP-KB926139
  -x86-ENU.exe
The batch file waits until WindowsXPKB926139- x86-ENU.exe terminates and only then goes to the next command. Occasionally some applications—usually very old ones—run a chain of their own application installations and exit before processes they’ve launched actually terminate. You’re unlikely to run into these older applications very often, but if you do, you can still use the batch file after adopting one of two strategies. Either place a single such application at the very end of the batch file, where it won’t matter that the /wait does you no good, or insert a Pause command in the batch file immediately after the line on which you run the installer:

start z:\dsp\legacy\oldapp.exe
echo wait for OldApp to finish
  installing && pause

Although it theoretically doesn’t help in this situation to use the /w option, it’s a good habit to use in creating scripts for setup chaining.

Set the Working Directory
On some occasions, you might need to control the working directory of the launched application. For example, some installers might use user-specific license files or need a local directory for extraction and not automatically get the user’s temp folder. You can force the working directory by using the /d option. If the application needs files from the OldAppData folder in the user’s profile, you can run it like this:

start /w /d %userprofile%\OldAppData
  z:\dsp\legacy\oldapp.exe

Handling Paths with Spaces
The single most significant problem people encounter when using the Start command is its behavior with file paths containing spaces. If you check the command-line options for the Start command, you’ll see why. Omitting some of the options for brevity, the Help display looks like this:

START ["title"] ... [command/program]

When the Start command sees a quoted string in its command line, Start assumes that you want to create a new window with the quoted string as the title. This means that if you try to run the installer z:\dsp\misc\Acme Shipping.msi by using the command

start /w "z:\dsp\misc\Acme Shipping.exe"

you won’t see the Acme Shipping.exe installer start. Instead, an empty command-prompt window will pop up with the title z:\dsp misc\Acme Shipping.exe.

Continue to page 2

   Previous  [1]  2  Next 


Windows IT Pro Community
Blogs





Top Viewed ArticlesView all articles
CES 2009: Ballmer Announces Windows 7, Windows Live, Live Search Milestones

During his first-ever Consumer Electronics Show (CES) 2009 keynote address last night in Las Vegas, Microsoft CEO Steve Ballmer announced the pending public availability of a feature-complete Windows 7, the final version of Windows Live Essentials, and ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Where is Microsoft NetMeeting in Windows XP?

...


Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Cloud Computing Forum: Integrating Software, Server and Storage as a Service into Your Enterprise IT Delivery Model

Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


SQL Server Magazine Office & SharePoint Pro Windows Dev Pro ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing