Monday, October 13, 2008

BIOS Serial Number as Computer name in Sysprep image

At a previous job about 18 months ago, I was asked to create a single SOE image that worked on many types of hardware, and was customizable to suit one of four organisations depending on which button the user clicked. It was an awesome challenge and I learned a lot from the experience.

One of the requirements of this Windows XP image was that the computer name of the machine had to be equal to that of the machine's serial number. That is, the hostname, and domain computer account, had to be exactly what your would yield if you used the WMIC command:

C:\> WMIC BIOS GET SerialNumber

I remember that this was quite difficult to achieve, and (for once) Google was of little assistance. There were a few hack 's suggested, like running a script on first start that would pull the value from WMI. But I was after a truely transparent experience which no user could stuff up, and which required no user intervention.

I did meet my deliverables on that project, and eighteen months down the track, I am writing this blog entry to you because it just occured to me that I probably should have shared this at the time to hopefully save people some time.

Setting the computer name to the machine's serial number in a sysprep build


1. Edit your sysprep.inf file and set the following value:


[UserData]
ComputerName=*COMPUTERNAME*

2. Copy and paste (and feel free to re-engineer my poor code) this into a file called GetSerialNumber.wsf


<job id="SetNameToSerial">
<script language="VBScript">
'Get Serial number from BIOS
Set objWMIService = GetObject("winmgmts:impersonationLevel=Impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)

FOR EACH item IN colItems
compname = item.SerialNumber
NEXT

'Edit sysprep.inf file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("sysprep.inf", 1)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "*COMPUTERNAME*", compname)
Set objFile = objFSO.OpenTextFile("sysprep.inf", 2)
objFile.WriteLine
strNewText
objFile.Close
</script>
</job>



3. Create a Winbom.ini file in preparation for a factory-mode sysprep (with mini-setup)

4. Use the [OEMRunOnce] secion to execute the script... The Winbom.ini file will look something *LIKE* this (I lost my copy!.. and CBF testing it):



[Factory]
Reseal = Reboot
ResealMode = Mini
WinbomType = Factory
UserName = Admin
Password = Password
[OEMRunOnce]
"Computername", "C:\windows\system32\wscript.exe GetSerialNumber.wsf"

5. You're done!

Now just do a factory mode sysprep.

Appologies that this probably wont work out of the box, as I havn't looked at this kind of stuff for 18+ months. I hope it helps. I'm sure this has been achieved by others, but when I needed the method, nobody had documented. I hope I've given you enough info to point you in the right direction. Good luck.

P.S. If you see people on the forums having trouble with this, send them my way :D