Solved

VBscript to change computername to service tag (Dell)

Posted on 2008-10-03
11
3,977 Views
Last Modified: 2013-11-10
Hi

Id like to add a vbscript to a sysprep to change the computername to the dell service tag. Ive done loads of searching but cant find anything that actually works. Can anyone advise?
0
Comment
Question by:k3eper
11 Comments
 
LVL 30

Expert Comment

by:flubbster
ID: 22633535
Perhaps this will help. Works on servers as well as individual PC's. Read all posts for use. You would need to add the code to rename the computer to the returned service tag at the end.

http://www.exchangepedia.com/blog/2005/04/getting-dell-service-tag-using-wmi.html
0
 

Author Comment

by:k3eper
ID: 22633668
Thanks for the response but i dont know any programming. I've found a few scripts to get the service tag but i have no idea how to use it to change the computer name. IE

 "attached"

and a few more that do similar things. Im after a script that will do it all for me. Get the tag and change computer name. Id imagine it cant be that difficult for someone that knows what they are doing?

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSMBIOS = objWMIService.ExecQuery _

("Select * from Win32_SystemEnclosure")

For Each objSMBIOS in colSMBIOS

Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber

Next

Open in new window

0
 
LVL 14

Expert Comment

by:igor-1965
ID: 22635360
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22635677
To change Computer icon?
Dim objShell : Set objShell = CreateObject("Wscript.Shell")
Dim objWMI : Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colSMBIOS = objWMIS.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
  objShell.RegWrite "HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\LocalizedString", objSMBIOS.SerialNumber, "REG_EXPAND_SZ"
Next

Or actual name?
const HKLM   = &H80000002

strKeyPath = "System\CurrentControlSet\Control\ComputerName\ComputerName"

Dim objReg : set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")

Dim objWMI : Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 

Set colSMBIOS = objWMIS.ExecQuery ("Select * from Win32_SystemEnclosure")

For Each objSMBIOS in colSMBIOS

  intRC = objReg.SetStringValue(HKLM, strKeyPath, "ComputerName", objSMBIOS.SerialNumber)

  if intRC <> 0 then

   WScript.Echo "Error setting ComputerName value: " & intRC

  else

   WScript.Echo "Successfully set ComputerName value to " & objSMBIOS.SerialNumber

  end if

Next

Open in new window

0
 

Author Comment

by:k3eper
ID: 22638332
Hi thanks for the help guys. I want a script that will fetch the service tag from bios (the serial if you like) and change the computer name to that tag. youll have to fogive my ignorance but the script above doesnt do anything but give me this error. Line: 6 Char: 1 Error: Object required :'objWMIS' Code: 800A01A8 Source: Microsoft VBscript Runtime Error. Id just like to say again i dont have any scripting knowledge. The script i have attached gives me the service tag and the second script i found prompts for the name i want to change the computer too. Can any of you make these work together to change the name in the backround.
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSMBIOS = objWMIService.ExecQuery _

("Select * from Win32_SystemEnclosure")

For Each objSMBIOS in colSMBIOS

Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber

Next 

(DONT COPY BELOW THIS LINE)___________________________________________________

__________________________________________________________________________
 

(((SECOND SCRIPT))COPY BELOW THIS LINE______________________________________________________________________
 
 

Dim pc, pcU, value1, value2, title, ws

Set ws = WScript.CreateObject("WScript.Shell")
 

value1 = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\"

value2 = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\"

title = "Windows XP Professional - Unattended Setup"
 

'--------------------------------Change ComputerName in Registry-------------------------------------

do

   pc = InputBox("Enter New Computername.", title)

   pcU= UCase(pc)

loop while pc=""
 

If pc <> "" Then

ws.RegWrite value1 & "ComputerName", pcU

ws.RegWrite value2 & "NV Hostname", pcU

End If

Open in new window

0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 67

Expert Comment

by:sirbounty
ID: 22638516
Sorry - that's basically what my 2nd script was supposed to do - I see I had a slight type-o...
Anyway - this is the combination of both scripts you posted:
strComputer = "."

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

Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")

For Each objSMBIOS in colSMBIOS

  strSN = objSMBIOS.SerialNumber

Next 

 

Set ws = WScript.CreateObject("WScript.Shell")

value1 = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\"

value2 = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\"

ws.RegWrite value1 & "ComputerName", strSN

ws.RegWrite value2 & "NV Hostname", strSN

Open in new window

0
 

Author Comment

by:k3eper
ID: 22644082
Thank you very much, it did indeed change my computer name but it changed it to 00C000E51011 looks like the serial number. The service tag for this particular machine im on at the moment is 1CYVD1J. If you run the script ive attached it shows you firstly the service tag then the serial number. Even tho it stats "Serial Number 1CYVD1J" on the first pop up then "Serial Number 00C000E51011" on the second pop up. id like the machine name changed to the service tag (First popup) rather than serial number (second popup). Hope that makes sense.
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSMBIOS = objWMIService.ExecQuery _

("Select * from Win32_SystemEnclosure")

For Each objSMBIOS in colSMBIOS

Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber

Next 

Open in new window

0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 22645232
Try this...
strComputer = "."

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

Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")

For Each objSMBIOS in colSMBIOS

  strSN = objSMBIOS.SerialNumber

  If strSN <> "" Then exit For

Next 

 

Set ws = WScript.CreateObject("WScript.Shell")

value1 = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\"

value2 = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\"

ws.RegWrite value1 & "ComputerName", strSN

ws.RegWrite value2 & "NV Hostname", strSN

Open in new window

0
 

Author Comment

by:k3eper
ID: 22646026
Aaar great works a treat thank you. Ive started learning Vbscript myself now. Thank you very much everyone. Cna anyone give me a good palce to learn from? WIth tutorials ect. Im a complete virgin to scripting.
0
 

Author Closing Comment

by:k3eper
ID: 31502731
Thank you so much this will save me a lot of time, and you have inspired me to learn for myself. :)
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22646855
Happy to help - thanx for the grade. :^)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now