在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中,你可以使用新的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.