我有奇怪的问题.
我使用的是Windows 7企业版sp1 64位.
我需要为我的项目获取程序文件和程序文件X86目录路径.这就是我所做的:
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
Run Code Online (Sandbox Code Playgroud)
但这两行都返回程序文件X86文件夹.
我该如何解决?
小智 56
这适用于x86,x64或任何CPU配置:
string programFiles = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
string programFilesX86 = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%");
Run Code Online (Sandbox Code Playgroud)
因为使用环境变量ProgramW6432将始终返回Program Files文件夹,而这ProgramFiles将根据您的应用程序编译选项而有所不同.
Mic*_*uda 18
结果取决于您的项目定位的平台.如果你的目标86,那么这两个Environment.SpecialFolder.ProgramFiles和Environment.SpecialFolder.ProgramFilesX86将返回相同的路径.