'
' Example VB Script for passing serial number from BIOS to WSName
'
' Edit Const's as required
'
' Note that some BIOS's may be require the serial number to be trimmed to
' fit within the allows 15 characters, my Toshiba Tecra 8100 for example
' returns : 70013268,PT810A-12C52,PMAT2A12C522/S3A0305D001
' The sticker on the back just says : 70013268J, as I can determine the
' manufacturer and model I can trim this down easily enough
'
' Some BIOS offer the ability to store asset information, I don't have access
' to one of these for testing but I assume the process will be very similar
'
' WMI support was introduced with Windows 2000 (?check this) so you'll need to
' use another mechanism to retrieve the serial number on these machines
'
Option Explicit
Const PATH_TO_WSNAME = "%systemroot\setup\BKB\WSNAME.EXE"
Const WSNAME_PARAMETERS = "/NOREBOOT"
Dim WSHShell1
Set WSHShell1 = WScript.CreateObject("WScript.Shell")
Dim strSerialNumber, strTEMP, strCommandLine, fso, WshShell
set fso = CreateObject("Scripting.FileSystemObject")
set WshShell = WScript.CreateObject("WScript.Shell")
'Check WSName exists
if not fso.FileExists(PATH_TO_WSNAME) then
WScript.Echo "ERROR, Could not find WSNAME in " & fso.GetParentFolderName(PATH_TO_WSNAME)
WScript.Quit(1)
end if
' --- Get the serial number, abort script on error
if Not GetWMIStuff("Win32_BIOS","SerialNumber",strSerialNumber) then
WScript.Echo "ERROR, Could not retrieve serial number"
WScript.Quit(1)
end if
' --- If we got this far then we have the serial number, if you want to see it
' --- uncomment the next line
' WScript.Echo "The raw serial number is " & strSerialNumber
' --- Tidy up the serial number, if required
strSerialNumber = TidySerialNumber(strSerialNumber)
' --- Uncomment the next line if you want to see it the result
' WScript.Echo "The tidied serial number is " & strSerialNumber
' --- Add leading Alpha characters to avoid DNS confusion
strSerialNumber="VWS-" & strSerialNumber
' strSerialNumber=strSerialNumber
' WScript.Echo "The tidied serial number is " & strSerialNumber
WSHShell1.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName", strSerialNumber
WSHShell1.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Reliability\LastComputerName", strSerialNumber
WSHShell1.RegWrite "HKLM\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName\ComputerName", strSerialNumber
WSHShell1.RegWrite "HKLM\SYSTEM\ControlSet001\Control\ComputerName\ComputerName", strSerialNumber
WSHShell1.RegWrite "HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Hostname", strSerialNumber
WSHShell1.RegWrite "HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters\NV Hostname", strSerialNumber
WSHShell1.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName", strSerialNumber
WSHShell1.RegWrite "HKLM\SYSTEM\CurrentControlSet\ControlSet\Control\ComputerName\ComputerName", strSerialNumber
WSHShell1.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname", strSerialNumber
WSHShell1.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", strSerialNumber
' --- Build Command Line, to check out the command line uncomment
strCommandLine = PATH_TO_WSNAME & " /N:" & strSerialNumber & " " & WSNAME_PARAMETERS
' WScript.Echo "About to run the following command:" & vbCRLF & vbCRLF & strCommandLine
' --- Now call WSName with the serial number
Call WshShell.Run(strCommandLine,1,FALSE)
' --- Game Over!
' ---------------------- Helper Functions ----------------------
Function GetWMIStuff(strInstance,strProperty,strResult)
Dim colWMIStuff, objWMI, propWMI
GetWMIStuff=False
Set colWMIStuff= GetObject("winmgmts:").InstancesOf(strInstance)
For Each objWMI In colWMIStuff
For each propWMI in objWMI.Properties_
If (Not IsNull(propWMI.Value) AND UCase(propWMI.Name) = UCase(strProperty)) Then
strResult=propWMI.Value
GetWMIStuff=True
Exit Function
End If
Next
Next
End Function
' --------------------------------------------------------------
Function TidySerialNumber(strSerialNumber)
Dim strModel
On Error Resume Next ' Turn off error checking
TidySerialNumber=strSerialNumber
Call GetWMIStuff("Win32_BIOS","Description",strModel)
if Instr(UCase(strModel),"TECRA8100") then ' This will a Tecra8100. I know how to tidy up.
TidySerialNumber=Left(strSerialNumber,Instr(strSerialNumber,",")-1) ' Trim at the first comma
end if
On Error Goto 0 ' Turn error checking back on
End Function
This topic area includes legacy versions of Windows prior to Windows 2000: Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions including Windows Mobile.
TRUSTED BY