In C#, how can I know programmatically if the Operating system is x64 or x86
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.
In .NET 4.0 you can use the new Environment.Is64BitOperatingSystem property.
And this is how it's 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With