Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing application data folder path for all Windows users

Tags:

c#

How do I find the application data folder path for all Windows users from C#?

How do I find this for the current user and other Windows users?

like image 367
Hema Joshi Avatar asked Jun 22 '10 08:06

Hema Joshi


2 Answers

This will give you the path to the "All users" application data folder.

string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
like image 199
hultqvist Avatar answered Sep 27 '22 21:09

hultqvist


Adapted from @Derrick's answer. The following code will find the path to Local AppData for each user on the computer and put the paths in a List of strings.

        const string regKeyFolders = @"HKEY_USERS\<SID>\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders";
        const string regValueAppData = @"Local AppData";
        string[] keys = Registry.Users.GetSubKeyNames();
        List<String> paths = new List<String>();

        foreach (string sid in keys)
        {
            string appDataPath = Registry.GetValue(regKeyFolders.Replace("<SID>", sid), regValueAppData, null) as string;
            if (appDataPath != null)
            {
                paths.Add(appDataPath);
            }
        }
like image 34
bubblesdawn Avatar answered Sep 27 '22 22:09

bubblesdawn