在C#中,我怎么能知道编程如果操作系统是基于x64或x86 [英] In C#, how can I know programmatically if the Operating system is x64 or x86

查看:400
本文介绍了在C#中,我怎么能知道编程如果操作系统是基于x64或x86的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我怎么能知道编程如果操作系统是基于x64或x86

In C#, how can I know programmatically if the Operating system is x64 or x86

我在互联网上找到此API方法,但它不工作

I found this API method on the internet, but it doesn't work

[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;
   }
}

在此先感谢。

Thanks in advance.

推荐答案

在.NET 4.0中,你可以使用新的<一个href="http://msdn.microsoft.com/en-us/library/system.environment.is64bitoperatingsystem.aspx">Environment.Is64BitOperatingSystem属性。

In .NET 4.0 you can use the new Environment.Is64BitOperatingSystem property.

这是它如何impemented

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

使用反射器或类似清楚地看到它是如何工作的。

Use reflector or similar to see exactly how it works.

这篇关于在C#中,我怎么能知道编程如果操作系统是基于x64或x86的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆