在C#中,如何以编程方式了解操作系统是x64还是x86

Hom*_*mam 4 .net c# 64-bit

在C#中,如何以编程方式了解操作系统是x64还是x86

我在互联网上找到了这种API方法,但它不起作用

[DllImport("kernel32.dll")]
public static extern bool IsWow64Process(System.IntPtr hProcess, out bool lpSystemInfo);

public static bool IsWow64Process1
{
   get
   {
       bool retVal = false;
       IsWow64Process(System.Diagnostics.Process.GetCurrentProcess().Handle, out retVal);
       return retVal;
   }
}
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Jes*_*alm 8

在.NET 4.0中,您可以使用新的Environment.Is64BitOperatingSystem属性.

这就是它的成功

public static bool Is64BitOperatingSystem
{
    [SecuritySafeCritical]
    get
    {
        bool flag;
        return ((Win32Native.DoesWin32MethodExist("kernel32.dll", "IsWow64Process") && Win32Native.IsWow64Process(Win32Native.GetCurrentProcess(), out flag)) && flag);
    }
}
Run Code Online (Sandbox Code Playgroud)

使用反射器或类似物来确切​​了解它是如何工作的.