How do you get the User Profile name in a Batch File without the complete path?

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.

4

1 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like