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.
我想给我的用户提供正确的链接,根据他们正在运行的平台升级我的程序,所以我需要知道我现在是运行在x86 OS还是x64操作系统上。
The best I've found is using Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
, but I would think there would be some built-in facility for this?
我发现的最好的方法是使用Environment.GetEnvironmentVariable(“PROCESSOR_ARCHITECTURE”),但是我认为会有一些内置的工具来实现这一点吗?
5 个解决方案
#1
5
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.
环境。Is64BitOperatingSystem和环境。is64bit进程正在。net 4中引入。对于。net 2,你需要尝试一些其他的答案。
#2
4
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.
调用IsWow64Process,查看您的32位进程是否在64位操作系统上运行。您可以调用GetNativeSystemInfo来确定它是什么:SYSTEM_INFO的wProcessorArchitecture成员将是processor_architecture - Intel的32位,processor_architecture - amd64是x64, processor_architecture - ia64是Intel的Itanium。
#3
0
Check the size of IntPtr with Marshal.SizeOf. 32 bit = 4 bytes, 64 bit = 8 bytes.
使用Marshal.SizeOf检查IntPtr的大小。32位= 4字节,64位= 8字节。
Edit: I am not sure this is what you are looking for after reading the question again.
编辑:我不确定这是你在再次阅读这个问题后所需要的。
#4
0
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]
您可以通过c#中使用的环境变量来确定许多内容——如何在Windows 64位上获得程序文件(x86)[这恰好比Mike的答案更适合我,因为我碰巧对查找程序文件目录名感兴趣)
#5
-2
Check just IntPtr.Size
. You need to have target platform as AnyCPU.
检查只是IntPtr。大小。您需要有目标平台作为任何cpu。
从这里
#1
5
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.
环境。Is64BitOperatingSystem和环境。is64bit进程正在。net 4中引入。对于。net 2,你需要尝试一些其他的答案。
#2
4
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.
调用IsWow64Process,查看您的32位进程是否在64位操作系统上运行。您可以调用GetNativeSystemInfo来确定它是什么:SYSTEM_INFO的wProcessorArchitecture成员将是processor_architecture - Intel的32位,processor_architecture - amd64是x64, processor_architecture - ia64是Intel的Itanium。
#3
0
Check the size of IntPtr with Marshal.SizeOf. 32 bit = 4 bytes, 64 bit = 8 bytes.
使用Marshal.SizeOf检查IntPtr的大小。32位= 4字节,64位= 8字节。
Edit: I am not sure this is what you are looking for after reading the question again.
编辑:我不确定这是你在再次阅读这个问题后所需要的。
#4
0
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]
您可以通过c#中使用的环境变量来确定许多内容——如何在Windows 64位上获得程序文件(x86)[这恰好比Mike的答案更适合我,因为我碰巧对查找程序文件目录名感兴趣)
#5
-2
Check just IntPtr.Size
. You need to have target platform as AnyCPU.
检查只是IntPtr。大小。您需要有目标平台作为任何cpu。
从这里