Ser*_*jev 12
Environment.SpecialFolder.ApplicationData
和 Environment.SpecialFolder.CommonApplicationData
这将为您提供"所有用户"应用程序数据文件夹的路径.
string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
Run Code Online (Sandbox Code Playgroud)
小智 7
改编自@ Derrick的答案.以下代码将为计算机上的每个用户找到Local AppData的路径,并将路径放在字符串列表中.
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);
}
}
Run Code Online (Sandbox Code Playgroud)