Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the Default Users folder (e.g. c:\users\Default)

Tags:

c#

.net

I've looked at the Environment.GetFolderPath method and the System.Environment.SpecialFolder enum but I couldn't see anything that returns the path of the Default Users folder.

Can someone please tell me how to get the Default Users folder (or even better the Default Users AppData Local folder path e.g. c:\users\Default\AppData\Local) programmatically as I need to copy some files into this folder?

Thank you

like image 533
m_collard Avatar asked Jun 14 '13 11:06

m_collard


1 Answers

There are lots of articles on the web that describe how to change the Default User Profile path:

http://support.microsoft.com/kb/214636

http://www.nextofwindows.com/how-to-change-user-profile-default-location-in-windows-7/

They all say the current Default Profile Path is stored in the following registry location:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

e.g. %SystemDrive%\Users\Default

And I found this page to get the System Drive: How to get current windows directory e.g. C:\ in C#

Path.GetPathRoot(Environment.SystemDirectory)

So I'm going to use that. Thanks for your help.

UPDATE

I've just tried the following code and it returns C:\Users\Default. So there is no need to replace the %SystemDrive% text stored in the registry key. It replaces it automatically.

using (RegistryKey profileListKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"))
{
    string defaultPath = profileListKey.GetValue("Default").ToString();
}
like image 170
m_collard Avatar answered Sep 23 '22 14:09

m_collard