Rename computer domain (VBScript)
This code can be found in
Chapter 2 of Windows Server Cookbook
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.
' This code renames a computer in its domain and on the computer itself.
' This script works only against Windows XP and Windows Server 2003 computers.
' ---------------------------------------------------------------
' From the book "Windows Server Cookbook" by Robbie Allen
' ISBN: 0-596-00633-0
' ---------------------------------------------------------------
' ------ SCRIPT CONFIGURATION ------
strComputer = "<ComputerName>" ' e.g. joe-xp
strNewComputer = "<NewComputerName>" ' e.g. joe-pc
strDomainUser = "<DomainUserUPN>" ' e.g. administrator@rallencorp.com
strDomainPasswd = "<DomainUserPasswd>"
strLocalUser = "<ComputerAdminUser>" ' e.g. joe-xp\administrator
strLocalPasswd = "<ComputerAdminPasswd>"
' ------ END CONFIGURATION ---------
' Connect to Computer
set objWMILocator = CreateObject("WbemScripting.SWbemLocator")
objWMILocator.Security_.AuthenticationLevel = 6
set objWMIComp = objWMILocator.ConnectServer(strComputer, _
"root\cimv2", _
strLocalUser, _
strLocalPasswd)
set objWMICompSys = objWMIComp.Get("Win32_ComputerSystem.Name='" & _
strComputer & "'")
' Rename Computer
intRC = objWMICompSys.Rename(strNewComputer, _
strDomainPasswd, _
strDomainUser)
if intRC <> 0 then
WScript.Echo "Rename failed with error: " & intRC
else
WScript.Echo "Successfully renamed " & strComputer & " to " & strNewComputer
end if
WScript.Echo "Rebooting system..."
Set colOS = objWMIComp.InstancesOf("Win32_OperatingSystem")
for each objOS in colOS
objOS.Reboot()
next
|
This code has been viewed 2158 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|