Contents

C#中的Environment 类有 Is64BitOperatingSystem 属性,可以判断当前操作系统是不是64bit的。还有Is64BitProcess 属性,可以判断当前进程是不是64bit的。

但是如果要判断别的进程是不是64bit的,就需要用windows API,IsWow64Process

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
static class ProcessDetector
{
public static bool IsWin64(Process process)
{
if (Environment.Is64BitOperatingSystem)
{
IntPtr processHandle;
bool retVal;

try
{
processHandle = Process.GetProcessById(process.Id).Handle;
}
catch
{
return false;
}
return Win32API.IsWow64Process(processHandle, out retVal) && retVal;
}

return false;
}
}

internal static class Win32API
{
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
}
Contents