Solved

VBscript to change computername to service tag (Dell)

Posted on 2008-10-03
11
4,167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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
 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

690 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