开发者

Accessing application data folder path for all Windows users

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

How开发者_如何学Python do I find this for the current user and other Windows users?


Environment.SpecialFolder.ApplicationData and Environment.SpecialFolder.CommonApplicationData


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

string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);


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);
            }
        }


The AppData folder for each user is stored in the registry.

Using this path:

const string regKeyFolders = @"HKEY_USERS\<SID>\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders";
const string regValueAppData = @"AppData";

Given a variable sid string containing the users sid, you can get their AppData path like this:

string path=Registry.GetValue(regKeyFolders.Replace("<SID>", sid), regValueAppData, null) as string;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜