BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

System Information
.NET 4.0+

Checking if the Operating System is 64-bit

64-bit versions of Windows behave differently than 32-bit operating systems when using unmanaged code and platform invocation services (P/Invoke). In some cases it is necessary to determine whether the operating system is a 32-bit or 64-bit version.

32-Bit and 64-Bit Operating Systems

In a recent article I described how you can check whether the current process is 32-bit or 64-bit. This allows you to vary the behaviour of your application depending upon how it is being executed. In some cases you may want your software to work differently based upon whether the operating system that it is running on is 32-bit or 64-bit.

Although these two pieces of information are related, they are not identical. If you detect that the process is running as 64-bit, this guarantees that the operating system is 64-bit too; you can't run a 64-bit process on a 32-bit version of Microsoft Windows. However, if the process is 32-bit, it is possible that the operating system is not.

To check the operating system, you can read the static Is64BitOperatingSystem property of the Environment class. This is shown in the sample below, which also uses Environment.Is64BitProcess. This code detects the number of bits for both the process and the operating system.

int processBits, osBits;

if (Environment.Is64BitProcess)
{
    processBits = osBits = 64;
}
else if (Environment.Is64BitOperatingSystem)
{
    processBits = 32;
    osBits = 64;
}
else
{
    processBits = osBits = 32;
}

Console.WriteLine("{0} bit process on {1} bit O/S", processBits, osBits);
19 September 2012