Main Page / Index

' RenameComp.vbs
' the script will ask for old & new computername, domain credentials and local admin credentials
' it will then attempt to start the registry service, rename the remote computer, and reboot it
' the input section could be modified to receive the 6 arguments passed from a text file if you need to
' change a bunch of computers. (old name, new name, domain admin credentials, local credentials)


' Input Section
sOld=InputBox("Old Name?")
sNew=InputBox("New Name?")
sDomainUser="InetDirect\" & InputBox("Domain Admin Username")
sDomainPasswd=InputBox("Password (NOT hidden!)")
sAdminUser=sOld & "\administrator" 'you may want add another Inputbox here if you use different accounts
sAdminPassword= "XXXXXXXX"         'you may want add another Inputbox here if you use different passwords

' Start Remote Registry - This snippet comes in handy for many things especially accessing W7
strService = " 'RemoteRegistry' "
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sOld & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name =" & strService & " ")
For Each objService in colListOfServices
   WSCript.Sleep 1500
   objService.StartService()
Next
WScript.Echo "Started " & strService & " on " & sOld

' Rename sOld
set oWMILocator = CreateObject("WbemScripting.SWbemLocator")
oWMILocator.Security_.AuthenticationLevel = 6
set oWMIComputer = oWMILocator.ConnectServer(sOld, "root\cimv2",sOld & sAdminUser,sAdminPassword)
set oWMIComputerSystem = oWMIComputer.Get("Win32_ComputerSystem.Name='" & sOld & "'")

rc = oWMIComputerSystem.Rename(sNew,sDomainPasswd,sDomainUser)
if rc <> 0 then
    WScript.Echo "Rename failed with error: " & rc
else
    WScript.Echo "Successfully renamed " & sOld & " to " & sNew
    WScript.echo "Now rebooting"
    RebootMachine sOld
end if

' Reboot Remote Machine - another very handy snippet
Sub RebootMachine(scompName)
    Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Security,Shutdown)}!\\" & scompName & "\root\cimv2")
    Set OS_Set = oWMI.Get("Win32_OperatingSystem")
    For Each os in OS_Set.Instances_()
      '*** Force Reboot ***
      ret = os.Win32Shutdown(6)
    Next
End Sub


Document made with Nvu