c# - 如何获取系统帐户下的所有用户应用程序数据文件夹?

标签 c#

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) 返回当前用户文件夹,但在系统帐户下它返回例如:

C:\Windows\system32\config\systemprofile\AppData\Roaming\

那么问题来了,如何通过系统账号获取所有用户的AppData文件夹?

最佳答案

我想,这可以帮助你:

//List all the users
List<String> usersList = new List<String>();
ManagementObjectSearcher sidQuery = new ManagementObjectSearcher("SELECT * FROM Win32_Account");
ManagementObjectCollection results = sidQuery.Get();
foreach (ManagementObject result in results)
{
   usersList.Add(result["Name"])
}

//Showing all the partitions letters 
String[] strDrives = Environment.GetLogicalDrives();
Foreach (string strDrive in strDrives)
{
  //Check if profil has AppData folder
  List<String> usersAppData = new List<String>();
  String pathAppData = String.Empty;
  foreach(String user in usersList)
  {
     pathAppData = String.Format("{0}\Users\{1}\AppData", strDrive, user);
     if(Directory.Exists(pathAppData ))
     {
        usersAppData.Add(pathAppData);
     }
  }
}

    //Here, you've got all the users AppData folder in usersAppData

关于c# - 如何获取系统帐户下的所有用户应用程序数据文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18017013/

相关文章:

c# - Entity Framework RC1 DbContext 查询问题

c# - 如何为 Windows 窗体中的文本框分配快捷键(如 Ctrl+F)?

c# - 如何阻止 XElement.Save 转义字符?

c# - 在 C# 中从任务管理器检测结束进程

C# 检查是否按下了多个键(全局键盘 Hook )

c# - 使用 JavaScriptSerializer 序列化 C# 对象会在 UTF8 字符串中产生无效字节

c# - 拦截每次鼠标点击 WPF 应用程序

c# - 如何将 C# 中的正则表达式代码转换为 C++

c# - 如何为 WS-Security 生成 UsernameToken?

c# - 如何在谷歌日历中创建 "recurData"?