Recently, from within an application, I needed to shell into a process. The challenge was that this process was different depending on whether it was being run started a 32 bit or a 64 bit environment.

In other words, in a 32 bit environment I needed to start process32.exe and from a 64 bit environment, I needed to start process64.exe.

There are a couple of solutions to this:

Check If The Operating System Is 64 Bit

In this approach, we check if the operating system itself is 64-bit using the Is64BitOperatingSystem property of the Environment class.

if (Environment.Is64BitOperatingSystem)
{
  //This is 64 bit
  Process.Start("process64.exe");
}
else
{
  // This is 32 bit
  Process.Start("process64.exe");
}

Check If The Process Is 64 Bit

In this approach, we check if the current process is 64-bit using the Is64BitProcess property of the Environment class.

if (Environment.Is64BitProcess)
{
  //This is 64 bit
  Process.Start("process64.exe");
}
else
{
  // This is 32 bit
  Process.Start("process64.exe");
}

TLDR

You can determine if an operating system is 32 or 64 bit, as well as the current executing process at runtime.

Happy hacking!