How to determine whether a System.Diagnostics.Process is 32 or 64 bit?

前端 未结 3 1752
遥遥无期
遥遥无期 2021-01-05 14:46

I tried:

process.MainModule.FileName.Contains(\"x86\")

But it threw an exception for a x64 process:

Win32Exception:

3条回答
  •  清歌不尽
    2021-01-05 15:16

    Neither WMI's Win32_Process or System.Diagnostics.Process offer any explicit property.

    How about iterating through the loaded modules (Process.Modules), a 32bit process will have loaded %WinDir%\syswow64\kernel32.dll while a 64bit process will have loaded it from %WinDir%\system32\kernel32.dll (this is the one dll that every Windows process loads).

    NB. This test will, of course, fail on a x86 OS instance.

提交回复
热议问题