views:

9129

answers:

6

Is it possible to change the hostname in Windows 2003 from the command line with out-of-the-box tools?

+1  A: 

I don't know of a command to do this, but you could do it in VBScript or something similar. Somthing like:

sNewName = "put new name here" 

Set oShell = CreateObject ("WSCript.shell" ) 

sCCS = "HKLM\SYSTEM\CurrentControlSet\" 
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\" 
sCompNameRegPath = sCCS & "Control\ComputerName\" 

With oShell 
.RegDelete sTcpipParamsRegPath & "Hostname" 
.RegDelete sTcpipParamsRegPath & "NV Hostname" 

.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName 
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName 
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName 
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName 
End With ' oShell 

MsgBox "Computer name changed, please reboot your computer"

Original

Geoffrey Chetwood
+4  A: 

The netdom.exe command line program can be used. This is available from the Windows XP Support Tools or Server 2003 Support Tools (both on the installation CD).

Usage guidelines here

Steven Murawski
A: 

Here's another way of doing it with a WHS script:

Set objWMIService = GetObject("Winmgmts:root\cimv2")

For Each objComputer in _
    objWMIService.InstancesOf("Win32_ComputerSystem")

    objComputer.rename "NewComputerName", NULL, NULL 
Next

Source.aspx)

axk
A: 

The netdom.exe command will do that. See http://shurl.us/ra/. You will have to install the Support Tools.

David Collantes
+1  A: 

wmic computersystem set Name=BlahComputer

I think 'Name' is the property you need. This WMIC should be built into XP/2K3 and above. Can't run it on my desktop, but I've practised with 'description' property. i.e. wmic computersystem set Desciprion="Preets Computer"

I do believe that you need to reboot,

Preet Sangha
I just tried doing this on W2K3E_R2 and got an error. Seems I have to do: `wmic computersystem get name` first to learn `OLDNAME` and then call: `wmic computersystem where name="OLDNAME" call rename name="NEWNAME"`
MikeyB
Thankyou for pointing that out.
Preet Sangha
A: 

Don't see a link to reply to the reply above (maybe noscipt blocking it), but here is my small improvement to the wmi command above:

> wmic computersystem where name="%COMPUTERNAME%" call rename name="NEW"
Gringo Suave