C#-如何在Windows 64位上获取程序文件(x86) [英] C# - How to get Program Files (x86) on Windows 64 bit
问题描述
我正在使用:
FileInfo(
System.Environment.GetFolderPath(
System.Environment.SpecialFolder.ProgramFiles)
+ @"\MyInstalledApp"
如果在用户计算机上检测到某个程序(这不是理想的选择,但是我正在寻找的程序是MS-DOS应用程序的正确选择,我想不到其他方法)。
In order to determine if a program is detected on a users machine (it's not ideal, but the program I'm looking for is a right old kludge of a MS-DOS application, and I couldn't think of another method).
在Windows XP和32位版本的Windows Vista上可以正常工作,但是,在x64 Windows Vista上,代码返回x64 Program Files文件夹,而应用程序安装在Program Files x86中。有没有一种方法可以以编程方式返回到程序文件x86的路径而无需硬接线 C:\程序文件(x86)?
On Windows XP and 32-bit versions of Windows Vista this works fine. However, on x64 Windows Vista the code returns the x64 Program Files folder, whereas the application is installed in Program Files x86. Is there a way to programatically return the path to Program Files x86 without hard wiring "C:\Program Files (x86)"?
推荐答案
下面的函数将在所有这三种Windows配置中返回x86 Program Files
目录:
The function below will return the x86 Program Files
directory in all of these three Windows configurations:
- 32位Windows
- 32位程序m在64位Windows上运行
- 在64位Windows上运行64位程序
static string ProgramFilesx86()
{
if( 8 == IntPtr.Size
|| (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
{
return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
}
return Environment.GetEnvironmentVariable("ProgramFiles");
}
这篇关于C#-如何在Windows 64位上获取程序文件(x86)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!