Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I name the conputer the serial number in the BIOS?

88 views
Skip to first unread message

Jack T.

unread,
Feb 15, 2003, 10:19:10 AM2/15/03
to
How can I automatically name a WORKGROUP computer the serial number
contained in the BIOS during install?

Thanks,
Jack T.


Torgeir Bakken (MVP)

unread,
Feb 15, 2003, 11:06:18 PM2/15/03
to
"Jack T." wrote:

> How can I automatically name a WORKGROUP computer the serial number
> contained in the BIOS during install?

Hi

You can use WMI (WMI is built-in for WinXP, and can be used from e.g. vbscript),
or you can use the command line utility compname.exe made by Oli Restorick.

Note that a computer name cannot contain only numbers, you need to add at least
one letter or a hyphen if the serial number in BIOS is only digits. Both methods
are described below.


==================================================
WMI/VBScript

Script below retrieves the BIOS serial number, adds a S in front of it and
renames the computer:


strComputer = "." ' use "." for local computer

strPrefix = "S" ' to be added to the BIOS serial number

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colBIOS = objWMIService.ExecQuery _
("Select SerialNumber from Win32_BIOS")

For Each objBIOS in colBIOS
sNewName = strPrefix & objBIOS.SerialNumber
Next

If sNewName <> strPrefix Then
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
intErrCode = ObjComputer.Rename(sNewName)
If intErrCode <> 0 Then
MsgBox "Error renaming computer, error # " & intErrCode
Else
MsgBox "Computer renamed, reboot needed! New name: " & sNewName
End If
Next
Else
MsgBox "Error renaming computer, could not read the BIOS SerialNumber"
End If


Rename Method in Class Win32_ComputerSystem
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/rename_method_in_class_win32_computersystem.asp


==================================================
Compname.exe

You can do this with the free command line utility compname.exe made by Oli
Restorick.

More info about compname here:

From: Torgeir Bakken (MVP) (Torgeir.B...@hydro.com)
Subject: Re: Rename server with vbscript
Newsgroups: microsoft.public.scripting.wsh
Date: 2002-10-28 09:14:07 PST
http://groups.google.com/groups?selm=3DBD6E02.F0D75A0%40hydro.com


From: Oli Restorick (use...@willowhayes.co.uk)
Subject: Changing computer name from command prompt (+SMBIOS)
Newsgroups: microsoft.public.win2000.cmdprompt.admin
Date: 2002-10-14 04:54:14 PST
http://groups.google.com/groups?selm=Ozn18R3cCHA.1704%40tkmsftngp10

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and a ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Jack T.

unread,
Feb 16, 2003, 9:10:07 AM2/16/03
to
They work perfectly!

Thanks,
Jack T.


Gary

unread,
Mar 4, 2003, 10:10:21 AM3/4/03
to
Has anyone used this script and gotten an error # 87?

Thanks!

-Gary

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message news:<3E4F0E3A...@hydro.com>...

0 new messages