Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if the executing program was compiled for 64 bit?

Tags:

c#

64-bit

I need for my program to determine if it was compiled for 32 bit windows or 64 bit/any CPU. I need to choose a different COM server flag depending on the compilation options. Any ideas?

like image 617
Steve Avatar asked Mar 11 '09 18:03

Steve


People also ask

How can I tell if an EXE is 64-bit?

Right-click on it or press and hold and then select Properties. Then go to the Compatibility tab. Here, check the "Run this program in compatibility mode for" box, and open the drop-down list. If the list starts with Windows Vista, then the application you selected is a 64-bit application.

How can I tell if my C# is 32 or 64-bit?

So we need to use the Is64BitOperatingSystem property of the Environment class. This property is used to check whether the running operating system is based on 64-Bit architecture or not and returns true if it is 64-bit OS otherwise it will return false.


3 Answers

Checking at run time if you are running a 64-bit application:

To see whether your process is 64-bit or 32-bit you can simply check the IntPtr.Size or any other pointer type. If you get 4 then you are running on 32-bit. If you get 8 then you are running on 64-bit.

What type of computer is your process running as:

You can check the PROCESSOR_ARCHITECTURE environment variable to see if you are running on an x64, ia64 or x86 machine.

Is your process running under emulation:

The Win32 API IsWow64Process will tell you if you are running a 32-bit application under x64. Wow64 means windows32 on windows64.

Contrary to what other people have posted: IsWow64Process will not tell you if you are running a 32-bit or a 64bit application. On 32-bit machines it will tell you FALSE for 32-bit applications when run, and on a 64-bit machine it will tell you TRUE for a 32-bit application. It only tells you if your application is running under emulation.

like image 51
Brian R. Bondy Avatar answered Sep 24 '22 13:09

Brian R. Bondy


Are you aware of Environment.Is64BitProcess? It determines whether the current running process is a 64-bit process.

like image 33
Lu55 Avatar answered Sep 22 '22 13:09

Lu55


You want the CORFLAGS command-line app from Microsoft. http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx

like image 29
Walden Leverich Avatar answered Sep 25 '22 13:09

Walden Leverich