使用以下命令:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
我得到以下输出:
"C:\\Documents and Settings\\[USER]\\Application Data"
如何获取所有用户的根目录?即:
"C:\\Documents and Settings\\[USER]\\"
发布于 2009-07-17 07:18:10
这可能是一个很好的解决方案:考虑到这是Vista/Win7还是XP,并且不使用环境变量:
string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
if ( Environment.OSVersion.Version.Major >= 6 ) {
path = Directory.GetParent(path).ToString();
}
不过,使用环境变量要清楚得多。
发布于 2009-07-16 21:30:22
尝试:
System.Environment.GetEnvironmentVariable("USERPROFILE");
编辑:
如果您使用的.NET版本为4或更高版本,则可以使用Environment.SpecialFolder
枚举:
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
发布于 2013-03-06 19:07:43
您只需使用以下命令即可获得UserProfile路径:
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
https://stackoverflow.com/questions/1140383
复制相似问题