C# 访问所有Windows用户的应用程序数据文件夹路径
如何从C#查找所有Windows用户的应用程序数据文件夹路径C# 访问所有Windows用户的应用程序数据文件夹路径,c#,C#,如何从C#查找所有Windows用户的应用程序数据文件夹路径 如何为当前用户和其他Windows用户找到此文件?Environment.SpecialFolder.ApplicationData和Environment.SpecialFolder.CommonApplicationData这将为您提供“所有用户”应用程序数据文件夹的路径 string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicat
如何为当前用户和其他Windows用户找到此文件?
Environment.SpecialFolder.ApplicationData
和Environment.SpecialFolder.CommonApplicationData
这将为您提供“所有用户”应用程序数据文件夹的路径
string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
每个用户的AppData文件夹都存储在注册表中 使用此路径:
const string regKeyFolders = @"HKEY_USERS\<SID>\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders";
const string regValueAppData = @"AppData";
const string regKeyFolders=@“HKEY\U用户\\软件\Microsoft\Windows\CurrentVersion\Explorer\Shell文件夹”;
常量字符串regValueAppData=@“AppData”;
给定包含用户sid的变量sid字符串,可以按如下方式获取其AppData路径:
string path=Registry.GetValue(regKeyFolders.Replace("<SID>", sid), regValueAppData, null) as string;
string path=Registry.GetValue(regKeyFolders.Replace(“,sid),regValueAppData,null)作为字符串;
改编自@Derrick的答案。下面的代码将为计算机上的每个用户找到本地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);
}
}
const string regKeyFolders=@“HKEY\U用户\\软件\Microsoft\Windows\CurrentVersion\Explorer\Shell文件夹”;
常量字符串regValueAppData=@“本地AppData”;
string[]keys=Registry.Users.GetSubKeyNames();
列表路径=新列表();
foreach(键中的字符串sid)
{
字符串appDataPath=Registry.GetValue(regKeyFolders.Replace(“,sid),regValueAppData,null)作为字符串;
if(appDataPath!=null)
{
添加(appDataPath);
}
}
+1用于特殊文件夹@Hema:请参阅,Environment.SpecialFolder.ApplicationData
提供漫游用户的文件夹。此路径仅在需要读/写访问权限时提供读访问权限检查此链接:这不是要求的。此路径需要提升的写入权限。