, vcldeveloper, , , .
(PID), , ( OP , ReadProcessMemory).
If the function for PID returns 0, this means that the process is most likely not running (or simply not found in the list of running processes)
function GetPIDbyProcessName(processName:String):integer;
var
GotProcess: Boolean;
tempHandle: tHandle;
procE: tProcessEntry32;
begin
tempHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0);
procE.dwSize:=SizeOf(procE);
GotProcess:=Process32First(tempHandle, procE);
{$B-}
if GotProcess and (procE.szExeFile <> processName) then
repeat GotProcess := Process32Next(tempHandle, procE);
until (not GotProcess) or (procE.szExeFile = processName);
{$B+}
if GotProcess then
result := procE.th32ProcessID
else
result := 0; // process not found in running process list
CloseHandle(tempHandle);
end;
Then we will get / open the process descriptor from the received PID. All code / usage is as follows:
var myPID, myProcessHandle: integer;
begin
myPID:=GetPIDbyProcessName('someExeName.exe');
myProcessHandle:=OpenProcess(PROCESS_ALL_ACCESS,False,myPID);
end;
You must save myProcessHandleso that it is available
ReadProcessMemory(myProcessHandle...)as the first parameter.
Also, add them to your global sentences:
Winapi.Windows(for ReadProcessMemory and OpenProcess)
Winapi.tlHelp32(to get the PID variable tProcessEntry32)
source
share