Microsoft – Change the Computer Name (Command Line)


To totally unlock this section you need to Log-in


Login

Sometimes we could have the need to rename a Windows system not from the usual GUI, but using command line (cmd.exe). Actually, this can be achieved by using the wmic command to rename a windows computer from command line. To do this, see the command below:

WMIC computersystem where caption='currentname' rename newname

Example: take an exmple system which has the current computer name as SYSTEM-1, to change it to SYSTEM-2: we can rename it by using the following command.

wmic computersystem where caption='SYSTEM-1 rename SYSTEM-2

After running the command, you need to reboot the computer to make the changes effective.

This command works on XP, Vista, Windows 7 and also on Server 2003 and Server 2008 editions (and above).

Obviously, this command can also be integrated and used from a batch file (.bat) to rename computer.

From Windows Vista and Windows 7 systems, and above, this rename command can be run only from elevated administrator command prompt, for security reasons (especially in Active Directory environments). If you run it from a normal command prompt, you would get the following error:

C:\>wmic computersystem where caption='xp-pc' call rename windows7-pc
Executing (\\XP-PC\ROOT\CIMV2:Win32_ComputerSystem.Name="XP-PC")->rename()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 5;
};
C:\>

If you are trying to rename a computer joined to a domain, then the computer should be online (same network of the domain) when you run the command. Otherwise you would get event error number 1355 with the following output:

C:\>wmic computersystem where caption='xp-pc' rename windows7-pc
Executing (\\XP-PC\ROOT\CIMV2:Win32_ComputerSystem.Name="XP-PC")->rename()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 1355;
};

Error 1355 means that the specified domain can’t be contacted. On successful execution of the command, the return value (exit code) would be 0 (zero).

Changing Name Remotely

If you’re a domain administrator and want to change a computer on the same network to a new name, use the following format:

wmic /node:"CURRENT" computersystem call rename "NEW"

For example:

wmic /node:"JON-LAPTOP" computersystem call rename "LAPTOPPC"

The value following /node: indicates the name of the remote computer on the LAN. You need to have administrative privileges on the remote computer or the following error will ensue, indicating Access is denied:

Microsoft - Change the Computer Name (Command Line)

If the user you are currently logged in with does not have administrative access to a networked computer, you can explicitly define credentials using the following format:

wmic /node:"CURRENT" /user:USERNAME /password:PASSWORD computersystem call rename "NEW"

For example:

wmic /node:"JON-LAPTOP" /user:ADMIN /password:PASSWORD123 computersystem call rename "LAPTOPPC"

Microsoft - Change the Computer Name (Command Line)

A system reboot is necessary for the changes to take effect.

1 thought on “Microsoft – Change the Computer Name (Command Line)”

  1. Take note that changing computer name (hostname) on Active Directory environment will break the connection of the host to the authorization and authentication server.

Comments are closed.