Rename computer (VBScript)

This code can be found in Chapter 1 of Windows Server 2003 Networking Recipes

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Windows Server 2003 Networking Recipes"

' This code renames the local computer to the name Computer2.
' ------ SCRIPT CONFIGURATION ------
  strComputer = "."
  strNewName = "Computer2"
' ------ END CONFIGURATION ---------

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
    errReturn = ObjComputer.Rename(strNewName)
    WScript.Echo "Computer successfully renamed"
Next

This code has been viewed 1758 times.

New from the creators of TechTasks.com: StatSheet.com