Reputation: 112907
I'd like to offer my users correct links to an upgraded version of my program based on what platform they're running on, so I need to know whether I'm currently running on an x86 OS or an x64 OS.
The best I've found is using Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
, but I would think there would be some built-in facility for this?
Upvotes: 5
Views: 2263
Reputation: 84794
Environment.Is64BitOperatingSystem and Environment.Is64BitProcess are being introduced in .NET 4. For .NET 2 you'll need to try out some of the other answers.
Upvotes: 5
Reputation: 61885
You can determine a lot via environment variables as used in C# - How to get Program Files (x86) on Windows 64 bit [And this happened to suit me better than Mike's answer which I +1'd as I happen to be interested in finding the Program Files directory name]
Upvotes: 0
Reputation: 9802
Call IsWow64Process
to find out if your 32-bit process is running in WOW64 on a 64-bit operating system. You can call GetNativeSystemInfo
to find out exactly what it is: the wProcessorArchitecture member
of SYSTEM_INFO
will be PROCESSOR_ARCHITECTURE_INTEL
for 32-bit, PROCESSOR_ARCHITECTURE_AMD64
for x64 and PROCESSOR_ARCHITECTURE_IA64
for Intel's Itanium.
Upvotes: 4
Reputation: 257
Check just IntPtr.Size
. You need to have target platform as AnyCPU.
Upvotes: -2
Reputation: 117310
Check the size of IntPtr with Marshal.SizeOf. 32 bit = 4 bytes, 64 bit = 8 bytes.
Edit: I am not sure this is what you are looking for after reading the question again.
Upvotes: 0