?
Solved

VBscript to change computername to service tag (Dell)

Posted on 2008-10-03
11
Medium Priority
?
4,227 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project
Suggested Courses

801 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