Before we start on making batch files to install our applications and registry tweaks, you may want to find out what they do and to see how they are used:
Batch files (*.cmd or *.bat, although *.cmd is recommended) can be executed in several areas of Windows XP's Setup process. Using batch files helps to automate several tasks at once without any interaction required.
They can be executed from either cmdlines.txt, svcpack.inf, a RunOnceEx entry in the Registry, or from the [GuiRunOnce] section in winnt.sif. You will learn more about these as you go through this guide.
» Typical contents of a batch file
Batch files supports all the commands that work as if you was using the Command Prompt. To see Windows XP's Command Prompt, go to Start > Run > and type cmd followed by enter.
Let's try making a small batch file that does several things. Open Notepad and copy and paste the following:
@echo off title Batch File Testing echo Hello World echo. echo Starting MS Paint start mspaint echo. echo Starting Wordpad start Wordpad echo. pause exit
Save this as anything you like, as long as it has a .cmd extension. Now double-click on the file. You will find that it renames the Window title to "Batch File Testing", opens MSPaint and Wordpad, asks you to press any key to continue, and then it exits.
|@echo off||Hides the C:\> Prompt and any commands shown in the batch file.|
|echo.||Includes a line spacing.|
|echo message||Prints "message" in a Command Prompt window, purely for commenting purposes.|
|title||Sets the title of the window.|
|start||Start an application, or an installation.|
|pause||Displays "Press any key to continue..."|
|exit||Exits the Command Prompt|
|sleep #||Pauses the execution of the batch script for # seconds, link on the download page.|
|cmdow @ /hid||Hides the batch file from view, useful if you don't want someone to cancel the process. Also on the download page|
Once you start adding software to your Unattended XP CD, you will find that most of the syntax on this site (in the Applications area) is shown as something like this:
Start "Title" /wait %systemdrive%\install\some_application\setup.exe /switch /anotherswitch
The Start command above will launch some_application's installation program, setup.exe. The /wait switch tells the Start command to wait for setup.exe to finish installing before proceeding to the next line of code in the script. It's important to use /wait so the rest of the script doesn't get executed all at once, which would most likely cause conflicts in the number of setup applications being run at the same time. The "Title" parameter tells Start what to name the Command Console opened by Start (if any). Always provide the "Title" parameter, even though using the Start command to open Windows-based programs normally does not result in opening an additional Command Console. Omitting the "Title" parameter will often cause the Start command to inaccurately process switches for the program it is launching. The /wait switch will not work correctly for some programs launched by the Start command—for example when the program Start launched subsequently launches another program and then terminates itself. Start only waits for the program it launched to terminate before allowing the script to proceed, yet the subsequently launched programs could still be executing. In such cases use Sleep to pause the script to allow these subsequent programs to complete.
Once you have a good understanding of using batch commands or want to find out more examples - check the Examples page.
» cmdlines.txt, svcpack.inf and [GuiRunOnce]
Scripts can also be run from cmdlines.txt or svcpack.inf, which runs at the T-13 / T-12 minute stage of Windows XP Setup. cmdlines.txt is useful for tasks such as Adding Users when using the net user method, or importing your HOKEY_CURRENT_USER registry tweaks to the Default profile. You will learn more about cmdlines.txt in the Reference section, and you may have used the SVPCACK.INF Method for installing hotfixes; just think of the batch file as another hotfix to add.
An example of a batch running from [GuiRunOnce]: Screenshot
As you can see in the screenshot, it's using a combination of "ECHO." and "ECHO message". It's not a requirement to use those, but it lets you know how it's progressing! [GuiRunOnce] is run on first logon.
» Where do I put the batch files?
For [GuiRunOnce], you can place them in any folder in the $OEM$ Distribution folders. For example, if you place batch_file.cmd in C:\XPCD\$OEM$\$1\install\ then you would insert this path under [GuiRunOnce] in winnt.sif, like so:
The Install folder specified at C:\XPCD\$OEM$\$1\Install\ is copied over to the systemdrive, so it turns out to be C:\install\ - More information on this can be found at the $OEM$ Distribution folders page.
For cmdlines.txt, it should be placed in the \$OEM$ folder, and does not need to be specified anywhere else to state its existence. Windows Setup automatically scans for a cmdlines.txt file. All batch files launched by cmdlines.txt should be put into the same folder.
svcpack.inf should go into the C:\XPCD\I386\ folder (make sure svcpack.in_ is deleted). Any batch files launched by svcpack.inf should go into the C:\XPCD\I386\svcpack\ folder unless otherwise specified by the entries in svcpack.inf, but more info on this is in SVCPACK.INF Method for Hotfixes.
» Next Step
Start adding your drivers and applications. This page was just meant to teach you about batch scripting and adding things to it.
Submitted by Alanoll.
Last updated 2006-04-17 14:15:18 by DarkShadows
Last updated 2006-04-17 14:15:18 by DarkShadows