16

I'm a Windows 7 user i used to change the username from the control panel. But I would like to know how to change it using the CLI not the GUI I have searched alot but didn't find the answer or it was unclear. A simple explanation to the code would be great

Joseph
  • 2,178

5 Answers5

21

You can use wmic for this. The command is:

wmic useraccount where name='currentname' rename newname

Example, if your username is "user" and you want to rename to "person" the following command would be used.

wmic useraccount where name='user' rename person

Please note, you need administrative privileges to use this command, so make sure you start your command prompt using run as administrator.

EDIT: suddenly you mention in the comments that you do NOT want to change the Username, but the Full Name instead.

The command for that is here:

wmic useraccount where fullname='currentname' rename newname

You can substitute fullname or name for any of the following:

AccountType  Description  Disabled  Domain    FullName     InstallDate  LocalAccount  Lockout  Name   PasswordChangeable  PasswordExpires  PasswordRequired  SID  SIDType  Status

You can use the following command to see a list of all users with all their settings:

wmic useraccount list
LPChip
  • 66,193
3

The following will do what you want:

net user JDoe /fullname:"John Doe"
kliu
  • 71
3

The wmic solution didn't work for me, and apparently WMIC is now deprecated as of Windows 10 21H1. The following worked for me in an elevated PowerShell, however:

(Get-WmiObject Win32_UserAccount -Filter "name='oldname'").Rename("newname")

This is also deprecated, apparently, but at least it works. I couldn't figure out the newer CIM methods without getting some sort of No mapping between account names and security IDs was done. error.

robbie
  • 131
3

If you're using powershell, you can also use the cmdlet Rename-LocalUser like this:

Rename-LocalUser -Name "Kylem" -NewName "kylemit"
KyleMit
  • 6,865
1

In my case wmic doesn't take effect, after lots of search, finally I find create another account and delete current account works.

Go to Control Panel > User Accounts, create a new account with new user name, and set it to Administrator. Then log out, and log in with new account, then delete the old account, it works.