访问所有Windows用户的应用程序数据文件夹路径
如何从C#中找到所有Windows用户的应用程序数据文件夹路径?
如何为当前用户和其他Windows用户找到此信息?
Environment.SpecialFolder.ApplicationData
和Environment.SpecialFolder.CommonApplicationData
这将为您提供“所有用户”应用程序数据文件夹的路径。
string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
改编自@ Derrick的答案。 以下代码将为计算机上的每个用户找到Local AppData的路径,并将路径放在字符串列表中。
const string regKeyFolders = @"HKEY_USERS\\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"; const string regValueAppData = @"Local AppData"; string[] keys = Registry.Users.GetSubKeyNames(); List paths = new List (); foreach (string sid in keys) { string appDataPath = Registry.GetValue(regKeyFolders.Replace("", sid), regValueAppData, null) as string; if (appDataPath != null) { paths.Add(appDataPath); } }
每个用户的AppData文件夹存储在注册表中。
使用此路径:
const string regKeyFolders = @"HKEY_USERS\\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"; const string regValueAppData = @"AppData";
给定包含用户sid的变量sid字符串,您可以像这样获取其AppData路径:
string path=Registry.GetValue(regKeyFolders.Replace("", sid), regValueAppData, null) as string;