【问题标题】:32 or 64 bit machine [duplicate]32 或 64 位机器 [重复]
【发布时间】:2011-11-11 13:34:24
【问题描述】:

可能重复:
How to detect Windows 64 bit platform with .net?

我正在使用此代码来检查机器是 64 位还是 32 位:

    public static string GetOSBit()
    {
        bool is64bit = Is64Bit();
        if (is64bit)
            return "64 bit";
        else
            return "32 bit";
    }

    [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);

    public static bool Is64Bit()
    {
        bool retVal;
        IsWow64Process(Process.GetCurrentProcess().Handle, out retVal);
        return retVal;
    }

我有一台 32 位机器,它对我来说没问题。它返回“32 位”。然而,我的朋友也有一台 32 位的机器,但安装了 64 位的虚拟机。上面的代码为她的虚拟机返回“32 位”,尽管它是 64 位的。 我在 C#、.Net 2.0 中工作。

【问题讨论】:

  • 正如 API 所暗示的,这描述了一个过程,而不是机器

标签: c# bit


【解决方案1】:

函数IsWow64Process判断指定进程是否在WOW64下运行。因此,在 64 位操作系统下运行的 32 位进程调用时,它基本上返回 true

【讨论】:

    【解决方案2】:

    您可以使用Environment.Is64BitOperatingSystem

    更多答案和讨论请见this question


    编辑:哦,没看到问题是关于 .net 2.0 的。 (保留答案以供参考。)

    【讨论】:

      猜你喜欢
      • 2011-02-05
      • 2012-01-16
      • 2011-06-02
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 2012-05-22
      • 1970-01-01
      相关资源
      最近更新 更多