I need determine when a process id (PID) is 32 or 64 bit application using delphi, how i can do that? I really check the IsWow64Process
function but works with a process handle not a PID.
Open the Task Manager by simultaneously pressing the Ctrl + Shift + Esc keys on your keyboard. Then, click on the Processes tab. In the Processes tab, you see the list of processes that are running at the moment. If a program is 32-bit, near its name you should see the text: *32.
Launch the target program you want to check if it's 32-bit or 64-bit, then open Task Manager and go to the Details tab. Right-click on a column header and choose Select columns. Check the Platform box, and click OK. Under the Platform column, you can easily see if a particular program on you system is 32-bit or 64-bit.
Note: If System Information isn't listed under Programs in the search results, click Programs to see more results. In the right pane, look at the System Type entry. For a 32-bit version operating system, it will say X86-based PC. For a 64-bit version, you'll see X64-based PC.
How to find if Linux is running on 32-bit or 64-bit. Open the Linux terminal application. Type uname -a to print system information. Run getconf LONG_BIT to see if Linux kernel is 32 or 64 bit.
You can use the OpenProcess
function to get a handle to the pid and then call the IsWow64Process
function.
Remember that you must load the IsWow64Process
function using the GetProcAddress
function because some versions of Windows does not include this function.
Check this sample code
{$APPTYPE CONSOLE}
uses
Windows,
SysUtils;
type
TIsWow64Process = function(Handle:THandle; var IsWow64 : BOOL) : BOOL; stdcall;
var
IsWow64Process : TIsWow64Process;
procedure Init_IsWow64Process;
var
hKernel32 : Integer;
begin
hKernel32 := LoadLibrary(kernel32);
if (hKernel32 = 0) then RaiseLastOSError;
try
IsWow64Process := GetProcAddress(hkernel32, 'IsWow64Process');
finally
FreeLibrary(hKernel32);
end;
end;
function PidIs64BitsProcess(dwProcessId: DWORD): Boolean;
var
IsWow64 : BOOL;
PidHandle : THandle;
begin
Result := False;
if Assigned(IsWow64Process) then
begin
//check if the current app is running under WOW
if IsWow64Process(GetCurrentProcess(), IsWow64) then
Result := IsWow64
else
RaiseLastOSError;
//the current delphi App is not running under wow64, so the current Window OS is 32 bit
//and obviously all the apps are 32 bits.
if not Result then Exit;
PidHandle := OpenProcess(PROCESS_QUERY_INFORMATION,False,dwProcessId);
if PidHandle > 0 then
try
if (IsWow64Process(PidHandle, IsWow64)) then
Result := not IsWow64
else
RaiseLastOSError;
finally
CloseHandle(PidHandle);
end;
end;
end;
begin
try
Init_IsWow64Process;
//here pass the pid which you want to check
Writeln(BoolToStr(PidIs64BitsProcess(1940),True));
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
Readln;
end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With