13

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

5 Answers 5

19

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
10
  • Yeah thanks I found this site too windows-commandline.com/wmic-useraccounts Dec 24, 2016 at 20:33
  • Please accept so others know you no longer require any help. And yes, this was literally the first site google found for me. Others would've voted your answer down for not taking any effort in searching.
    – LPChip
    Dec 24, 2016 at 20:35
  • but i need to change the full name not the name Dec 25, 2016 at 12:38
  • Your question says how to change windows user name. If you now suddenly talk about the full name, then you have to specify your question better.
    – LPChip
    Dec 25, 2016 at 13:00
  • 1
    @LPChip's answer works great on Windows 10 Pro (and as @gaborous mentioned, it was the only way I could find to fully change the username in Windows 10). However, I had to restart my computer in order for the new username to take effect. Jun 12, 2020 at 15:51
3

The following will do what you want:

net user JDoe /fullname:"John Doe"
2

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.

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.

0

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

Rename-LocalUser -Name "Kylem" -NewName "kylemit"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .