How can I get the current user directory?

juan picture juan · Jul 16, 2009 · Viewed 134.6k times · Source

Using this:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

I get this output:

"C:\\Documents and Settings\\[USER]\\Application Data"

How can I get the root directory of all users? i.e.:

"C:\\Documents and Settings\\[USER]\\"

Answer

Thomas picture Thomas · Jul 16, 2009

Try:

System.Environment.GetEnvironmentVariable("USERPROFILE");

Edit:

If the version of .NET you are using is 4 or above, you can use the Environment.SpecialFolder enumeration:

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);