Add Intelligence to Sysprep
When doing sysprep on a Windows XP disk image, the answer file Sysprep.inf is very limited. It cannot let you check computer model and use specific settings. Now new dual-core computers are getting popular. However, Sysprep cannot intelligently select the right hardware abstraction layer (HAL) nor allow users to configure a HAL by the computer model.
To solve this problem, we have to look at how a Sysprep'ed image set up. During setup, Preinstallation Environment (PE) is loaded first, and then PE runs the command line at the Registry HKLM\SYSTEM\Setup\CmdLine to start the setup process. The command line for Mini-Setup is "setup.exe -newsetup -mini". What we can do is to change the command line to execute our own setup and then our own setup executes the original Setup.exe.
Most of settings in Sysprep.inf are read and used in Mini-Setup. During execution of our own setup, we can modify Sysprep.inf before Mini-Setup touches it. Updating HAL is one of things Mini-Setup does. With the information form computer's SMBIOS and CPU, we can put a proper HAL setting to Sysprep.inf.
MySysprep consists of only one executable MySysprep.exe. It should be placed in Sysprep directory along with Sysprep.exe. MySysprep.exe can be used as a replacement for Sysprep.exe. MySysprep.exe eventually will invoke Sysprep.exe and pass on all command arguments. Basically, if you run MySysprep.exe to reseal an image with Mini-Setup. MySysprep.exe installs an executable MySetup.exe into the system directory, executes Sysprep.exe, and when Sysprep.exe exits, it changes the Registry key HKLM\SYSTEM\Setup\CmdLine to use MySetup.exe.
MySysprep can merge manufacturer, model, serial number specific settings into Sysprep.inf. To enable this feature, you need to have a file named MySysprep.inf, which may contain three sections [Manufacturer], [Model], and [SerialNo]. If MySysprep find an entry under those sections, which matches the manufacturer, model, or serial number in SMBIOS, the anser file specified in that entry will be merged into Sysprep.inf. For example, the model name in SMBIOS is TravelMate8200, and we want Mini-Setup to update HAL to multiprocessor for this model. In MySysprep.inf, we can configure to merge Tm8200.inf into Sysprep.inf if the model name is TravelMate8200,
In Tm8200.inf, we put the the following entry to update HAL.
Before running MySysprep.exe, you have to make sure the required HAL or kernel files exist in the system directory.
You can also specify a pattern of model names or serial numbers with wildcard characters. However, you have to put them in a section named [Model Like] or [SerialNo Like] in MySysprep.inf. For example,
If the model name matches the pattern of TravelMate*, the answer file tm_all.inf will be merged into Sysprep.inf. Wildcard characters are listed in the following table.
|*||Any string of zero or more characters.|
|?||Any single character.|
|[ ]||Any single character within the specified range ([a-f]) or set ([abcdef]).|
|[!]||Any single character not within the specified range ([!a-f]) or set ([!abcdef]).|
To check the manufacturer, model, and serial number setting in a computer's BIOS, you can use the following command.
MySysprep can also detect the number of a CPU's logical processors. This feature is implemented by using the CPUID instruction to query the vendor ID and the logical processor count (inlcuding Hyper-Threading and multi-core) . To use this feature, a section [CPU] has to be added to MySysprep.inf. The entry name is the vendor ID with a ".MP" or ".UP" suffix. MP is for multi-processor, while UP is for uni-processor. For example.
If the vendor ID is GenuineIntel and the logical processor count is greater than 1, The answer file mp.inf will be merged to Sysprep.inf. If the logical processor count is 1, the answer file up.inf will be merged.
Intel processors have the vendor ID: GenuineIntel, while AMD processors have AuthenticAMD.
This feature will not work on computers with multiple CPU sockets. Besides the settings of a computer's BIOS may limit the capability of a multi-core or Hyper-Threading processor to one logical processor. The CPUID instruction only reports the full capability of a processor.
To check if MySysprep can detect a CPU, the following command can be used.
The merge order will start from [CPU] followed by [Manufacturer], [Model Like], [Model], [SerialNo Like] and finally [SerialNo]. The same entry in the latter one will overwrite the entry in the former one.
To verify the result of merging, you can open $winnt$.inf in the system directory after booting the image on a test target. The file in fact is a copy of Sysprep.inf done by Mini-Setup with the product key removed.
Caveat 1: The PE is running on the HAL which the image was created on. If the HAL is not compatible with the target computer, PE may have troubles to start. The HAL, Advanced Configuration and Power Interface (ACPI) PC, is compatible with most computers. It is a good idea to use it when creating an image, and update HAL through UpdateHAL or UpdateUPHAL.
Caveat 2: The settings in Sysprep.inf are used in different stages. MySysprep works on those settings which are used during Mini-Setup. For example, the entry OEMDuplicatorString is read and put to the Registry key HKLM\SYSTEM\Setup when Sysprep.exe is run. The section SysprepMassStorage is also used during Sysprep for loading PE in the future. Updating those entries has no effect at all.
With MySysrep, the setting ComputerName under the section [UserData] in Sysprep.inf can be formated with the computer's manufacturer, model, or serial number, and asset tag from SMBIOS. To know what they are configured in SMBIOS, you can use the following command line.
Four variables %Manufacturer%, %Model%, %SerialNo% and %AssetTag% can be used to format the computer name. For example, to use the serial number as a part of the computer name.
You can also take substring from %Manufacturer%, %Model%, %SerialNo% and %AssetTag% by specified the starting index and the length of the substring in the format (start,length) inserted before the closing %. For example, to take the first four characters from the manufacturer name, you can use %Manufacturer(0,4)%. To take the third character to the end of the serial number, you can use %SerialNo(2,-1)%.
You can combine the variables as you like. For example, you want the first four characters from the manufacturer, followed by a dash, and then followed by the serial number. You can use the following format.
Caveat: The manufacturer, model, serial number or asset tag in SMBIOS may content invalid characters for a computer name, and the length of a computer name is limited. If your computer name format results in an invalid computer name, Mini-Setup will reject it and ask the user to input a valid one.
MySysprep is in action.
You should always have copies of your disk images. The author is not responsible for any damages of hardware, software, or data resulting from using this software.
Added %AssetTag% for configuration of a computer name
Added CPU vendor ID and logical processor count match
Added wildcard pattern match for model and serial number