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/