Getting the Script Ready to Try
142 C HAPTER 5 SETTING UP AND ROLLING OUT WINDOWS SERVER
Warning Note that you should keep the list of directories to 40 or fewer characters. This is a limitation of OEMPnP- DriversPath. But don’t make them single-character directory names, or Setup will try to create files on drive C:, D:, E:, etc., on the target machine!
Tell Setup to Run Commands with cmdlines.txt
Once your system is set up, you might want to install some applications beyond the basic operating system, or you might want to delete some little-used files that Setup leaves behind, or you might want to accomplish any number of other small tasks. You can do that with a file named cmdlines.txt,
which must be located in the $OEM$ directory.
cmdlines.txt is just a list of command-line commands that you want Setup to execute. That may
sound to you as if I’m suggesting that cmdlines.txt is an old DOS-style batch file, but it isn’t. For
some reason, it needs a specific format. The first line must be [Commands] on a line all by itself. Then, you list the commands that you want Setup to run—but you must surround the commands with double quotes. For example, consider this example cmdlines.txt file:
[Commands]
"msiexec /i \\server\share\somefile.msi" "regedit /s myhacks.reg"
As you see, the first line is just [Commands]. Then, the second line is the first command that you want Setup to run. If you’ve never heard of MSIEXEC, then let me introduce you—it’s a command that you’ll use a lot when building cmdlines.txt files. You see, under Windows 2000, XP, and
Server 2003, you install an application using a service called the Windows Installer service. Instead of installing programs with a traditional setup.exe program, you install programs by handing a
“package” to the Installer. This package is the collection of files that you need to run the program, as well as a set of instructions about how to install the program—“this file goes here, this icon goes on the Start menu, create these Registry entries”—and the Installer looks at the instruction file (which, by convention, has the extension .msi) and carries out its instructions. (You’ll learn more
about this in the chapter on software deployment; I’m just giving you the barest of sketches about how it works here.)
Normally you deploy an MSI-type package using Active Directory, as you’ll learn a bit later in this book. But if you want to install an application from the command line, then you’ll use a program called msiexec.exe. The /i option says to install the program from its MSI, silently. Again, you’ll
learn more about where you get MSI files from a bit later in the book—I just thought that an msiexec /i example would be useful.
Tip In order to make this work, msiexec.exe must be in the $OEM$ directory; copy it from a functioning Windows 2000 or later OS.
The second command may be familiar to experts in any NT version from 4 on. Sometimes the easiest way to set up NT, 2000, or Server 2003 to work exactly the way you want is to apply a bunch of Registry hacks. The REGEDIT command offers a pretty neat command-line way to modify the Registry.
For example, I find the AutoRun feature of CD-ROMs really annoying. I don’t want Server 2003 offering to install every time I pop the Server 2003 CD into a drive just to get a file or two. Now, I could
PERFORMING UNATTENDED INSTALLS: AN OVERVIEW 143
shut off AutoRun by opening up a Registry Editor, navigating down to HKEY_LOCAL_MACHINE\SYSTEM\ CurrentControlSet\Services\Cdrom, and then editing the entry labeled AutoRun, setting its value
to 0. But I don’t want to hand-edit the Registry—and that’s where REGEDIT comes to the rescue. Just create a four-line ASCII file (call it CDFix.reg) with these contents:
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom] "AutoRun"=dword:00000000
Note the blank line between REGEDIT4 and [HKEY; you need that. Now open up a command line and tell REGEDIT to apply this change by typing regedit /s cdfix.reg; the /s means, “Shut up and do it!” so you won’t get a message. But reboot your NT or later machine and you’ll find that AutoRun is now disabled. Notice how what I could call the REGEDIT “command language” works: the first line is REGEDIT4, then a blank line, then you indicate what key you want to work with, in brackets, and then the value entry. And that line starting with [HKEY_LOCAL_MACHINE is just one line when typed, no matter how long. You can put a whole bunch of changes into a single file, or create different .reg files and apply them sequentially.
As with msiexec.exe, be sure to put regedit.exe in the $OEM$ folder, or this won’t work. And you
may be wondering, how did I figure out how to create a file in “REGEDIT format?” Simple. I just highlighted a key that I wanted to apply and then exported it. The exported file turned out to be a simple ASCII format—and an import showed that REGEDIT imports files in the same format as it exports.
Using CMDLINES.TXT to Install the Latest Hotfixes
Here’s an even more valuable use for cmdlines.txt: preinstalling hotfixes. Hotfixes are files that
fix some critical problem in NT 4 or later, things that will eventually make their way into the next service pack but that Microsoft felt were important enough that they couldn’t wait for the next service pack. You can find them by going to www.microsoft.com/security and then clicking the Security Bulletins
link. Now, that works as of the time that I am writing this, but Microsoft is fond of rearranging their Web site, so if that doesn’t work, then just do a search for “security bulletins” on their site and you’ll find them. For step 1, download them and collect them into the $OEM$ directory. They’ll have names
like q329834_WXP_SP2_ENU.exe, which tells you
◆ that you can find out about what this fixes in Knowledge Base article 329834, ◆ that you apply this to Windows XP Pro (WXP),
◆ that it is post-Service Pack 2, and
◆ that it works on the version of the operating system that is localized for English.
If you’ve ever applied a hotfix, then you know that you just run it as a program, which is nice and simple. But what’s not so simple is that every time you install a hotfix, the stupid hotfix insists that you reboot the computer. Let’s see, 16 hotfixes in the post-SP2 world (to use XP as an example)… figure a minute a reboot… I’ve only got 1000 computers to do this on. Naaah. But there’s good news. Fortunately, most hotfixes written since mid-2002 have two options, -q and -z, that tell the hotfixes to install quietly and not to force a reboot.