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);
    }

相关文章:

  • 2021-11-29
  • 2021-12-30
  • 2021-06-10
  • 2021-10-30
  • 2021-10-17
  • 2021-12-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
相关资源
相似解决方案