Build image and change the computername to the system serial number  

with help from Jeff Bunting (Mike_Niccum@BeverlyCorp.com)

 http://www.clarksupport.com/Scripts.htm

 

PROBLEM:

 

I wanted to have a process automatically change the computername to the serial number of the workstation in an unattended fashion before SYSPREP started.

 

SOLUTION:

 

Use a vbscript (using WMI) to grab the serialnumber of the workstation and place it in the sysprep.inf before sysprep.exe starts.

 

 Note:  This process has been tested on a Dell Optiplex and Compaq Deskpro EN SFF...

 

REQUIREMENTS:
A.  Windows 2000 Professional
B.  Workstation must support WMI, built in to Win2k.
C.  Workstation must have a serial number.
D.  Workstation must have Windows Scripting Host installed, installed by default on Win2k.

 

INSTRUCTIONS:

 

1.  Prepare a Workstation to the point where you are ready to image it.

 

2.  Create a folder called C:\Sysprep

 

3.  Copy Sysprep.exe, Sysprep.inf, Setupcl.exe, and Pnpids.exe (Pnpids.exe not required)

    Note 1:  Make sure the COMPUTERNAME= line in the sysprep.inf is changed to COMPUTERNAME=####

    Note 2:  I have not configured the sysprep.inf to have the Workstation join the domain...

 

Here is a SAMPLE Sysprep.inf that you can modify to fit your environment:

 

;SetupMgrTag
[Data]
    AutoPartition=1
    MsDosInitiated=0
    UnattendedInstall=Yes

 

[Unattended]
    OemSkipEula=Yes
    TargetPath=\WINDOWS
    InstallFilesPath=

 

[GuiUnattended]
    AdminPassword=password    ;this needs to be changed
    Autologon=Yes
    AutoLogonAccountCreation=Yes
    AutologonCount=1
    OEMSkipRegional=1
    TimeZone=20
    OemSkipWelcome=1
    EncryptedAdminPassword=Yes
    OEMDuplicatorstring="Windows 2000 Professional Image"

 

[UserData]
    ProductID=XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
    FullName=name                                                    

    OrgName=company
    ComputerName=####

 

[Display]
    BitsPerPel=24
    Xresolution=1024
    YResolution=768

 

[Branding]
    BrandIEUsingUnattended=Yes

 

[Proxy]
    Proxy_Enable=0
    Use_Same_Proxy=1

 

[Identification]
    JoinWorkgroup=workgroup

 

[Networking]
    InstallDefaultComponents=Yes

 

;[GuiRunOnce]
;    Command0=c:\scripts\file.bat

 

 

4.  Paste the following into notepad and save as C:\Sysprep\Startup.reg:

 

Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx]

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001]
"ComputerName"="c:\\sysprep\\serial.vbs"

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\002]
"sysprep"="c:\\sysprep\\sysprep.exe -reboot -quiet"

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]

"DefaultUserName"="Administrator"

"AltDefaultUserName"="Administrator"

"AutoAdminLogon"="1"

"DefaultPassword"="password"

 

4a.  Change the "DefaultPassword"="password" to your local administrator password

 

5.  Paste the following into notepad and save as C:\Sysprep\Serial.vbs:

 

 'prep
 dim Bios, BiosSerial, objFSO, objTextFile
 'Const ForReading = 1, ForWriting = 2, ForAppending = 8

 

 'get serial number
 for each Bios in GetObject("winmgmts:").InstancesOf ("win32_bios")
 BiosSerial = Bios.SerialNumber
    exit for
 next

 

' Unrem the next line to make sure the BiosSerial is being collected successfully

' Msgbox "Serial Number = " + BiosSerial, yes

 

 'open file and read into memory, replace #### with serialnumber
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 r="c:\sysprep\sysprep.inf"
 Set objTextFile = objFSO.OpenTextFile(r,1)
 s = objtextfile.readall
 n = "####"
 snew = Replace(s,n,BiosSerial)
 objTextFile.close
 set objtextfile=nothing

 

 'delete old file
 objfso.DeleteFile r, true

 

 'write new file
 set objTextFile = objfso.CreateTextFile(r)
 objTextFile.Write snew
 objTextFile.Close
 set objTextFile = nothing

 

' Unrem the next line to make sure the vbscript is running successfully

' Msgbox "Computername changed to " + BiosSerial", yes

 

6.  Open Explorer and double-click on C:\Sysprep\Startup.reg, press YES and then press OK.
7.  Shutdown the Workstation.
8.  Image the Workstation with your favorite imaging software.

 

What happens next?

 

1.  Put your new image on a new Workstation.

 

2.  On reboot, the Workstation will autologon

 

3.  The C:\Sysprep\Serial.vbs will execute from the RunOnceEX\001 key and change the c:\sysprep\sysprep.inf to reflect the current serial number as the computername.

 

4.  The C:\Sysprep\Sysprep.exe will execute from the RunOnceEX\002 key with the -reboot and -quiet switches. (both 001 and 002 keys will be removed before next boot)

 

5.  The Workstation will automatically reboot.

 

6.  On reboot the Workstation will autologon and run c:\Sysprep\Sysprep.exe and use the new C:\Sysprep\Sysprep.inf, in turn changing the computername to the current serial number.

 

7.  Setupcl.exe will change the SID.

 

8.  After C:\Sysprep\Sysprep.exe finishes, the C:\Sysprep folder will be deleted and the workstation will reboot.

 

9.  On reboot the workstation will stop at the logon prompt.

 

10.  Please note that the registry still holds the autoadminlogon password, but the autoadminlogon is not enabled.  You may want to script a way to remove the password for security reasons.  A simple vbscript could accomplish this.  The password is in the startup.reg if you need to reference it.