This is a small VBS script file that will when ran, gets the serial number from the computers WMI host, which gets it from the BIOS, and then renames the computer to this. The main reason I created this was to run at login here at work on our Active Directory domain, where all the computers are Dell, and have their names in the directory updated to the serial numbers from Dell. This file will need to be modified with your username and password that has admin rights to the machine, and if running on a domain, you will need to specify a domain username and passwords with rights to change computer names on the domain. Also, this script has been made to run on Windows XP Professional only. We blocked out Windows 2000 Professional, to find those workstations and upgrade them with time. Remember, all my stuff is available to you, just make sure you take care with the use of my files, and know that if you break something, it's your ass.
strUser = "Administrator"
strPassword = "P@ssw0rd"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
strMsg = objItem.Caption
If strMsg = "Microsoft Windows XP Professional" Then
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//."
'WScript.Echo winmgmt1
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
for each SN in SNSet
If SN.SerialNumber = strComputer Then
MsgBox "Computer name already set! Name is: "& strComputer
Wscript.Quit
End If
If SN.SerialNumber = "" Then
MsgBox "Problem with computer naming!"
Wscript.Quit
End If
ErrCode = objComputer.Rename(SN.SerialNumber, strPassword, strUser)
If ErrCode = 0 Then
MsgBox "Computer renamed successfully to: "& SN.SerialNumber
End If
Next
End If
Next