troubleshooting Question

Prepend Text to variable in VBS

Avatar of zequestioner
zequestioner asked on
ProgrammingVB Script
2 Comments1 Solution520 ViewsLast Modified:
Hello Experts,

I found a nifty script to rename a computer but I would like to prepend the computername with my own text.

For example, the script below sets the computername to the manufacturer serial number. (For example: "GLM6742YZ")

http://www.bluemoonpcrepair.com/software/scripts/changecomputername-Win7.vbs

I would like to prepend my own text to this to help identify the location of the computer.

For example: "EAU-GLM6742YZ"

I'm sure it's right here:

'Part 2 - Assign computer name to serial/service tag number
Name = strSN

But I can't seem to figure out the syntax to add the extra text...

Please help!

Thanks!


'***********************************************************************
'
' changecomputername-Win7.vbs
' Changes the computer name to the computer's serial number/service tag.
' A message is displayed if an error occurs, or if the result is success.
'
' Joe Grossi - June 11, 2010
' FMCNA
'
'***********************************************************************


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

'Part 1 - Acquire serial/service tag number
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
  strSN = objSMBIOS.SerialNumber
  If strSN <> "" Then exit For
Next



'Part 2 - Assign computer name to serial/service tag number
Name = strSN

Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
    err = objComputer.Rename(name)

if err <> 0 then
 wscript.echo "There was an error renaming the machine. Please restart, and try again."
else
 wscript.echo "Machine successfully renamed: " & Name
end if

Next
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros