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
wmic computersystem where caption='DESKTOP-TDMECML' rename
Slartibartfast to change the
name from DESKTOP-TDMECML to Slartibartfast 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 the name change was successful, you will see a return value of zero. 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 five 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.
If you issue the hostname command afterwards, you will still
see the old name even when the name change has been successful. 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: