I am looking for a solution for this after struggling for most of the day. In short my dilemma seems simple. An effective solution appears elusive based on the Google and Stackoverflow hits I've had on this one.
(EDIT)
I need to clarify the use-case. We may have 6 users needing to run certain scripts that use the "%USERNAME%
" string to login to case-sensitive environments, Linux, MySQL, etc. One user-name is mixed-case. In the example I used my name: "Will" for the scripts it must-be: "will" (all lower-case).
- The general question though is how can the %USERNAME% environment variable value be change when it is mis-entered?
At present my Windows 7 Professional username is "will" but the environment variable has this value:
echo. User = %USERNAME%
User = Will
I need it to come-out as:
User = will
rem * All lower-case
To be clear ...
I want to change (source) value Windows sets the USERNAME environment variable when I login.
I thought it would be easy to find the setting or config option to change that string -- Until I tried. I think this must happen frequently judging from questions related to getting a USERNAME to work with cygwin, etc.
The question
Bothers me too, because that's a messy script to "fix" something basic in a login-environment.
I did a quick survey around the office as well. Some people have mixed case, one or two have lowercase. It seems arbitrary depending on what was typed-in when account was created or something.
Our admin guy looked up my account on the domain (no, not active directory) and is same as my login-screen, "will" (lowercase).
Finally I did a couple of experiments. I changed my username in the Users control panel
from: "will" to "xxwill"
Thinking that would surely update my USERNAME string. I logged out. I did it again and rebooted a second time. The result was extremely surprising (or maybe it shouldn't have been):
User = Will
rem * NO change for the "xxwill" name-change!
Some further grist. I created an account "dodo" and account "Dogdo" and changed the usernames to "Dodo" and "dogdo" respectively.
User = dodo
User = Dogdo
rem * NO change for name-changes!
I see that the USERNAME can't be altered that way. I can't edit the system environment variable in the Advanced options. It may be in the profile. But can you edit a profile or even look inside it with just Administrator powers? I don't know yet; I'm not sure that's my preferred route either since it is hacking with a bit of "output" from some original setting, somewhere.
I hope someone can set me straight so I don't need that script-solution.
@ECHO OFF
SETLOCAL
PUSHD "%temp%"
COPY NUL "%username%" >NUL 2>NUL
FOR /f "delims=" %%a IN ('dir /L /b "%username%"') DO set "usernamelc=%%a"
del "%username%" >NUL 2>NUL
POPD
ECHO %USERNAME% --^> %usernamelc%
GOTO :EOF
Perhaps this may help. YMMV.