Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I just installed Windows XP in my virtualbox on windows 7 host. I can't change the username environment variable:

USERNAME=Owner

I successfully changed the variable USERDOMAIN because it is defined in the system properties in control panel. But I can't figure out where USERNAME is defined. I wonder if modifying it will have an impact on the variable:

USERPROFILE=C:\Documents and Settings\Owner

I have changed my username in my user account but it has no effect on the system variable USERNAME.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The environment variable USERNAME is defined in the registry key HKEY_CURRENT_USER\Volatile Environment.

Note however that as the keyname implies, the variables in this key are volatile, meaning that while the user can change them, they will not retain their new values and will be overwritten by the system with derived values (sort of like registry RAM). The username environment variable is one of the few variables that cannot be set, or even if they are, they will not “stick”, just like how setting a variable in a console session is lost when you open a new one.

It should update the variable with the new user name. Have you tried logging out and back in or rebooting the system?


Where/how did you change the user name, the User Accounts Control Panel applet? The User Accounts applet only changes the user’s name, not the actual username. Use lusrmgr.msc to modify the user name by clicking it, pressing F2 and changing it (then log out/in or reboot).

If that does not work, then search the registry for the old/original user name and change it there(s?). Check the following keys:

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList
share|improve this answer
    
I did logout and reboot but still the same. That's odd. I don't have a USERNAME value in the registry in the windows xp in virtualbox but I have this CLIENTNAME, though but it has no value. I have the USERNAME reg_sz in my windows 7 host but not in xp. –  WikiWitz Dec 25 '11 at 6:13
    
Hmm, they must have removed it in XPSP2. Either way, it is not something you can set. It is an ephemeral/transient/dynamic environment variable. In other words, the OS sets it each time you log in, based on the currently logged in user. You’ll want to forget about trying to find/change the variable because it is not something that would stick even if you could change it. I’ll update my answer to give an idea of something else to accomplish what you want… –  Synetech Dec 25 '11 at 19:33
    
Thanks there. Using the lusrmgr.msc to modify the USERNAME environment variable did change it, and permanently. Since USERNAME does not exist under the volatile environment key, it is not volatile in my Windows XP guest OS. However in my Windows 7 host, it is under that registry key and is changed by the OS automagically. And by the way, Synetech. It was the "USERDOMAIN" that I was able to change in the control panel. Regarding whether the USERPROFILE variable will be affected by the change of the USERNAME variable, I found this article: <en.wikipedia.org/wiki/Microsoft_Windows_profile> –  WikiWitz Dec 26 '11 at 8:43
    
If you want to change the USERPROFILE variable, then locate the target account in the registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList and change the ProfilesDirectory value then log out&in (or reboot) and Windows should update it. –  Synetech Dec 27 '11 at 20:45
    
What do you mean by that? The value in my registry is %systemdrive%\users. And the USERPROFILE is unchangeable. It is permanent even if you change the USERNAME variable. –  WikiWitz Dec 28 '11 at 2:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.