Detecting CPU Structure in .Net Framework

The title seems simple, just getting CPU structure to detect if your program running on an AMD64 or an Intel x86 machine.
Remember when you install a 32-bit operation system on a 64-bit machine then all features are 32 bit so your program supports only 32-bit processor and can’t be a 64-bit one even if your CPU is x64.
By the way I search a lot across the Internet for getting the answer but almost all of them gives me , wrong information and that’s because whenever you try to get information about CPU in current PE then the result is same as current running PE structure and in almost all the situations developers set their program to support both x86 and x64 so the final EXE file will be an x86 one and you can’t correctly get CPU Type.
The following code gives you the desired result :

Remember if you build your application just for x64 machines then your CPU is always x64.
That’s obvious. 😀

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.