Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why doesn't this work? it looks like it will but nothing happens.

Option Explicit

Dim wshNetwork
Dim wshShell
Dim PCname
Dim Newname

Set wshNetwork = WScript.CreateObject("WScript.Network")
Set wshShell = WScript.CreateObject("WScript.Shell")

PCname = InputBox("Type in the name of the pc you want to rename")
Newname = InputBox("Type in the name of the new pc name")"netdom renamecomputer " &PCname& " /NewName:"&Newname& " /reboot:00 " )
'MsgBox("netdom renamecomputer " &PCname& " /NewName:"&Newname& " /reboot:00 /y")
share|improve this question

I've encountered this before and while I know how to do it through PowerShell, you might want to try this if your looking for VBS.

Taken from

CONST adOpenStatic = 3
CONST adLockOptimistic = 3
CONST adCmdText = &H0001
CONST intWindowStyle = 7
CONST blnWait = TRUE
DIM strCSVFolder,strCSVFile,strNetDomParams
DIM objShell,cn,rs

' ************** Setup ************** 
' Folder where CSV File is located
' CSV file should have 1st field = oldname, 2nd field = newname with no header row
strCSVFolder = "C:\Temp\"
' CSV filename
strCSVFile = "test.csv"
' Additional parameters to pass to NetDom command
strNetDomParams = " /userd:DOMAIN\ADMINISTRATOR /passwordd:PASSWORD /usero:DOMAIN\ADMINISTRATOR /passwordo:PASSWORD /force "


SET objShell = wscript.CREATEOBJECT("")

' Setup ADO Connection to CSV file

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=" & strCSVFolder & ";" & _
          "Extended Properties=""text;HDR=NO;FMT=Delimited"""

rs.Open "SELECT * FROM [" & strCSVFile & "]", _
          cn, adOpenStatic, adLockOptimistic, adCmdText

DO until rs.eof
    DIM strOldName, strNewName, strCmd,intReturn
    strOldName = rs(0)
    strNewName = rs(1)
    strCmd = "cmd.exe /C netdom renamecomputer " & strOldName & " /newname:" & strNewName & strNetDomParams

    intReturn = objShell.Run(strCmd,intWindowStyle,blnWait)

    IF intReturn = 0 THEN
        wscript.echo "Renamed '" & strOldName & "' to '" & strNewName & "'"
        wscript.echo "Error renaming '" & strOldName & "' to '" & strNewName & "'" 
    END IF

share|improve this answer

Shelling out to the cmd line is always a pain (plus you gotta make sure netdom is there), dealing with quotes in VB and what not.

Probably easier to just go native and use WMI, and as a bonus should work most anywhere. This will join a domain too (you can remove that portion), but you could just leave the rename portion and the reboot portion and you should be good.

This is untested code that I lifted from another site.


Dim sCmpName
Dim sUser, sPassword, sDomain, sOU

sUser = "<domainuserid>"
sPassword = "<domainpassword>"
sDomain = "<mydomain>"
sOU = "<ou=myou,dc=mydomain,dc=com>"

sCmpName = InputBox("Enter the new computer name:", "Computer Name")
If sCmpName = "" Then
  Wscript.Echo "Exiting script."
End If

Dim oWMI, oCmp, oOS, sReturn

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
For Each oCmp in oWMI.InstancesOf("Win32_ComputerSystem")
  sReturn = oCmp.Rename(sCmpName)
  If sReturn <> 0 Then
    Wscript.Echo "Rename failed.  Error = " & Err.Number & _
      vbcrlf & "Exiting script."
    Wscript.Echo "Rename successful."
    sReturn = oCmp.JoinDomainOrWorkgroup(sDomain, sPassword, _ 
      sDomain & "\" & sUser, sOU, JOIN_DOMAIN+ACCT_CREATE)
    If sReturn <> 0 Then
      Wscript.Echo "Join domain failed.  Error = " & Err.Number & _
        vbcrlf & "Exiting script."
  Wscript.Echo "Join domain successful."
End If
Wscript.Echo "Rebooting computer..."
For Each oOS in oWMI.InstancesOf("Win32_OperatingSystem")
  sReturn = oOS.Reboot
End If
share|improve this answer

if you try to deploy an VM image: have you just tried to run sysprep^(1)?! This also forces (as far as I know) the system to reset SID informations preventing WSUS problems and so on!?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.