What are the rules regarding casing of values for environment variable USERNAME in Windows?

Posted on

A server stack is the collection of software that forms the operational infrastructure on a given machine. In a computing context, a stack is an ordered pile. A server stack is one type of solution stack — an ordered selection of software that makes it possible to complete a particular task. Like in this post about What are the rules regarding casing of values for environment variable USERNAME in Windows? was one problem in server stack that need for a solution. Below are some tips in manage your windows server when you find problem about windows, active-directory, authentication, environment-variables, windows-authentication.

One of my customers says that in his AD usernames have mixed case sometimes and besides that, that people are able to successfully login using another casing of usernames. So there might be an ExampleUser in the AD and Windows allows them to login with exampleUSER etc. as well.

But what is the impact on the environment variable USERNAME?

I have tested a bit myself without an AD and in all of my tests USERNAME had the value of the username as it has been created. So in case of ExampleUser created in Windows, using the login EXAMPLEuser provided ExampleUser as USERNAME. That happened for RDP where users are free to input usernames as well as using runas.

My customer said that this is not the case for him at least sometimes, but instead if ExampleUser in the AD logs in using exampleUSER, USERNAME really contains the value of the current login, exampleUSER. I’ve found another question describing that as well:

For some users in this office, %USERNAME% is always in the case they type it when logging in.

For other users, %USERNAME has until recently always been in the canonical case (for a user logging in as elenasimpson it returns ElenaSimpson), but last week mysteriously started only doing this sometimes and the rest of the time returning it as typed. Rebooting often toggles to the other behaviour.

What I did not found is any official docs from MS of what is the value of USERNAME under which setups and inputs of users. Are there any rules one can rely on?


Active Directory is case aware, but not case sensitive. I can’t seem to find a Microsoft document directly on it, but that is the case. What that means, is the first time a user logs into a computer and they use EXAMPLEuser, it will create the user folder with that case. If you use ExampleUser, it will also use that case for that new computer.

I might double check to see if the customer is comparing apples to apples. Does he have a domain or a work group? Is he using an app that is case aware? Can he log into the same computer with the two “different” accounts? If it’s on a domain, compare the two accounts Common Name, pre-Windows 2000 logon, and userPrincipalName.

Leave a Reply

Your email address will not be published.