C#判断一个进程是不是64位的
C#中的Environment 类有 Is64BitOperatingSystem 属性,可以判断当前操作系统是不是64bit的。还有Is64BitProcess 属性,可以判断当前进程是不是64bit的。
但是如果要判断别的进程是不是64bit的,就需要用windows API,IsWow64Process
。
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); }