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

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

相关文章:

  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-10-19
  • 2021-12-05
  • 2021-12-06
猜你喜欢
  • 2022-12-23
  • 2022-01-31
  • 2021-07-23
  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
相关资源
相似解决方案