gpt4 book ai didi

C# - 如何在 Windows 64 位上获取程序文件 (x86)

转载 作者:IT王子 更新时间:2023-10-29 03:31:26 26 4
gpt4 key购买 nike

我正在使用:

FileInfo(
System.Environment.GetFolderPath(
System.Environment.SpecialFolder.ProgramFiles)
+ @"\MyInstalledApp"

为了确定是否在用户机器上检测到程序(这并不理想,但我正在寻找的程序是 MS-DOS 应用程序的一个正确的旧程序,我想不出另一种方法).

在 Windows XP 和 32 位版本的 Windows Vista 上,这工作正常。但是,在 x64 Windows Vista 上,代码返回 x64 Program Files 文件夹,而应用程序安装在 Program Files x86 中。有没有办法以编程方式返回到 Program Files x86 的路径,而无需硬连接“C:\Program Files (x86)”?

最佳答案

下面的函数将返回所有这三种 Windows 配置中的 x86 Program Files 目录:

  • 32 位 Windows
  • 在 64 位 Windows 上运行的 32 位程序
  • 在 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),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/194157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com