Changing the host name for a Windows system from a command prompt

There are a variety of ways you can determine the system name for a Windows computer from a command line interface (CLI), such as a command prompt or PowerShell prompt window. But what if you wish to rename the computer from a command line interface? You can obtain a command prompt and then use a Windows Management Instrumentation Command-line (WMIC) command in the form shown below where oldname is the curent name of the system and newname is the new name you wish to assign to the system.

wmic computersystem where caption='oldname' rename newname

You can use the hostname command to view the current name for a system.

C:\WINDOWS\system32>hostname
DESKTOP-TDMECML

C:\>

For the system above, I could then use the command below to change the name from a command prompt window with administrator privileges.

C:\WINDOWS\system32>wmic computersystem where caption='DESKTOP-TDMECML' rename Slartibartfast
Executing (\\DESKTOP-TDMECML\ROOT\CIMV2:Win32_ComputerSystem.Name="DESKTOP-TDMECML")->rename()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 0;
};


C:\WINDOWS\system32>

If you try to change the computer name from a command prompt window where you have only regular user privileges, you will see a return value of 5 as in the message shown below and the name won't actually be changed:

C:\>wmic computersystem where caption='DESKTOP-TDMECML' rename Slartibartfast
Executing (\\DESKTOP-TDMECML\ROOT\CIMV2:Win32_ComputerSystem.Name="DESKTOP-TDMECML")->rename()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 5;
};


C:\>

Note: This command should work on Windows XP, Vista, Windows 7, 8, 8.1, and 10 and also on Server 2003 and Server 2008 editions.

To have the name change take effect, you will need to reboot the system, which you can do from a command prompt with administrator privileges using the shutdown command, specifically shutdown /r /f. The /r option is used for a full shutdown and restart while the /f option forces running applications to close without forewarning users. The /f parameter is implied when a value greater than 0 is specified for the /t parameter. You can add a /t xxx option, where xxx is the number of seconds to wait before commencing the shutdown process. Make sure that any unsaved work you may have in progress on the system is saved prior to issuing the command.

C:\WINDOWS\system32>shutdown /r /f

C:\WINDOWS\system32>

Related articles:

  1. Determining the system name for a computer running Windows 10
  2. Obtaining a Command Prompt on a Windows 8 System
  3. Obtaining a command prompt in Windows 10