Contents

下面的代码能判断一个process是32bit还是64bit.

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