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?
环境.Is64BitOperatingSystem和Environment.Is64BitProcess正在.NET 4中引入。对于.NET 2,您需要尝试其他一些答案。
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.
您可以通过C#中使用的环境变量来确定很多- 如何在Windows 64位上获取程序文件(x86) [这恰好比迈克的答案更适合我,因为我碰巧有兴趣寻找Program Files目录名]
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.
Check just IntPtr.Size
. You need to have target platform as AnyCPU.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.