Link to home
Start Free TrialLog in
Avatar of zequestioner
zequestioner

asked on

Prepend Text to variable in VBS

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
ASKER CERTIFIED SOLUTION
Avatar of dsacker
dsacker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zequestioner
zequestioner

ASKER

I was trying Name = ("EAU-"  & "strSN") but this works perfectly! Thanks!