troubleshooting Question

Prepend Text to variable in VBS

Avatar of zequestioner
zequestioner asked on
VB ScriptProgramming
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")

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!


' 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

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

'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."
 wscript.echo "Machine successfully renamed: " & Name
end if

Contract ERP Admin/Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
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