I've seen that you can use %USERNAME% to get the whole path but I just want to get e.g John Doe for use in mapping a network drive to specific folders named after the user profile names?
e.g NET USE h: \test\Citrixusers\%USERNAME% but of course this gets the username as C:\Users\"Name"
So the end result would be like \test\Citrixusers\John Doe
Thanks in advance all.
41 Answer
How do you get the User Profile name in a batch file?
without the complete path
It appears you are confusing %USERNAME% and %USERPROFILE%.
%USERNAME%contains just the username.%USERPROFILE%contains the profile path (which includes the username).
Standard (built-in) Environment Variables
Variable Default value in Windows 7/2008
...
USERNAME {username}
USERPROFILE %SystemDrive%\Users\{username}
Source environment variables - Environment variables are mainly used within batch files, they can be created, modified and deleted for a session using the SET command.
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.