Is Process 64bit

Tiny snippet to know whether or not target process id is running under 32bit or 64bit architecture.

If result is True, target process is running under 64bit architecture.

If result is False, target process is running under 32bit architecture.

//
// Jean-Pierre LESUEUR @DarkCoderSc
//

// ...

uses Windows, SysUtils;

// ...
type
  TArchitecture = (x86, x64, xUnknown);
// ...

function IsProcessX64(AProcessId : Cardinal) : TArchitecture;
var AProcHandle   : THandle;
    AWow64Process : bool;
begin
  result := xUnknown;
  ///

  {
    If we are not in a 64Bit system then we are for sure in a 32Bit system
  }
  if (TOSVersion.Architecture = arIntelX86) then
    Exit();
  ///

  AProcHandle := OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, False, AProcessId);
  if AProcHandle = 0 then
    Exit;
  try
    isWow64Process(AProcHandle, AWow64Process);
    ///

    if AWow64Process then
      result := x86
    else
      result := x64;
  finally
    CloseHandle(AProcHandle);
  end;
end;
comments powered by Disqus