Setting the Name of a Server

Using a graphical user interface

  1. From the Control Panel, open the System applet.
  2. Select the Computer Name tab (or Network Identification on Windows 2000).
  3. Click the Change button (or Properties on Windows 2000).
  4. Enter the new name in the Computer name field.
  5. If the computer is a member of the domain, you will be prompted for credentials to use for renaming the account in the domain unless you are logged in with a domain administrator account.
  6. Click OK.
  7. Click OK to confirm that you’ll need to restart (this won’t actually restart the computer).
  8. Click OK again.
  9. Click Yes if you want to restart now or No to restart later.

Using a command-line interface

Use this command to display the current computer name:

> hostname

The compname.exe utility, which is available from, can also display the current computer name:

> compname /s

But this command can also do a whole lot more. This changes a computer’s name:

> compname /c <NewServerName>

The truly powerful feature of compname is its ability to name a system based on certain variables (or what it calls templates). You can name a computer based on its serial number, UUID, MAC address, and date, among other things. The following example changes a computer name to contain its serial number at the end:

> compname /c pc-?s

Run compname /? for more information on the available templates.

This is a registry-based method for setting a computer’s name:

> reg add \\<CurrentServerName>\HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v "NV Hostname" /d <NewServerName>> reg add \\<CurrentServerName>\HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /d <NewServerName>> shutdown \\<CurrentServerName> /r

If the computer is already part of a domain and you use either the compname or registry methods, the computer’s domain account will become out of sync and it will no longer be able to function in the domain. To rename a computer that is part of a domain, use the netdom.exe command:

> netdom renamecomputer <CurrentServerName> /newname:<NewServerName> /userd:<DomainUserName>

Using VBScript

' This code changes the name of a computer.  It does NOT modify' the computer's account in the domain if one exists.' ------ SCRIPT CONFIGURATION ------strComputer = "<CurrentServerName>"strNewName = "<NewServerName>"' ------ END CONFIGURATION ---------const HKLM   = &H80000002strKeyPath   = "System\CurrentControlSet\Control\ComputerName\ComputerName"set objReg = GetObject("winmgmts:\\" & strComputer & _                       "\root\default:StdRegProv")intRC = objReg.SetStringValue(HKLM, strKeyPath, "ComputerName", strNewName)if intRC <> 0 then   WScript.Echo "Error setting ComputerName value: " & intRCelse   WScript.Echo "Successfully set ComputerName value to " & strNewNameend ifstrKeyPath   = "System\CurrentControlSet\Services\Tcpip\Parameters"intRC = objReg.SetStringValue(HKLM, strKeyPath, "NV Hostname", strNewName)if intRC <> 0 then   WScript.Echo "Error setting NV Hostname value: " & intRCelse   WScript.Echo "Successfully set NV Hostname value to " & strNewNameend if

WScript.Echo "Rebooting system..."set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")for each objOS in objWMI.InstancesOf("Win32_OperatingSystem")   objOS.Reboot( )next

' 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.' ------ SCRIPT CONFIGURATION ------strComputer     = "<ComputerName>"       ' e.g., joe-xpstrNewComputer  = "<NewComputerName>"    ' e.g., joe-pcstrDomainUser   = "<DomainUserUPN>"      ' e.g., administrator@rallencorp.comstrDomainPasswd = "<DomainUserPasswd>"strLocalUser    = "<ComputerAdminUser>"  ' e.g., joe-xp\administratorstrLocalPasswd  = "<ComputerAdminPasswd>"' ------ END CONFIGURATION ---------' Connect to Computerset objWMILocator = CreateObject("WbemScripting.SWbemLocator")objWMILocator.Security_.AuthenticationLevel = 6set objWMIComp = objWMILocator.ConnectServer(strComputer, _                                        "root\cimv2", _                                             strLocalUser, _                                             strLocalPasswd)set objWMICompSys = objWMIComp.Get("Win32_ComputerSystem.Name='" & _                                   strComputer & "'")' Rename ComputerintRC = objWMICompSys.Rename(strNewComputer, _                             strDomainPasswd, _                             strDomainUser)if intRC <> 0 then    WScript.Echo "Rename failed with error: " & intRCelse    WScript.Echo "Successfully renamed " & strComputer & " to " & strNewComputerend if

WScript.Echo "Rebooting system..."Set colOS = objWMIComp.InstancesOf("Win32_OperatingSystem")for each objOS in colOS   objOS.Reboot( )next

Setting the name of a computer is a straightforward operation, but it does require a reboot. If the computer is member of an Active Directory domain, the corresponding computer account must also be renamed. Some of the solutions I described do this automatically and some do not.

In some cases, renaming a computer can adversely affect services running on the computer. For example, you cannot rename a machine that is a Windows 2000 domain controller, Exchange 2000 or 2003 server, or a Windows Certificate Authority without first removing those services.

Using a command-line interface

The renamecomputer option in netdom is new to Windows Server 2003. You can run it against a remote computer and it includes a /Reboot option that allows you to automatically reboot the computer after the rename is done.

Using VBScript

The Win32_ComputerSystem::Rename method must be run on the local machine unless the computer is a member of a domain. Unlike the graphical and command-line solutions, you cannot specify alternate credentials for the connection to the computer other than domain credentials. For this reason, the user and password you use with the Rename method must have administrative privileges on the target machine (i.e., part of the Administrators group) and on the computer object in Active Directory.