Lol grad eben wollte ich auch meine jetzt funktionierende Version schreiben.
Ich machs einfach mal:
Benötigte Uses: Windows, Tlhelp32;
Delphi-Quellcode:
const
THREAD_SUSPEND_RESUME = $0002;
function PauseProcess(PID: DWORD; F_Pause: boolean): boolean;
var NewThread: Cardinal;
ThreadSnap: HWND;
Te32: THREADENTRY32;
begin
ThreadSnap := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
If ThreadSnap = INVALID_HANDLE_VALUE Then
Begin
Result := False;
Exit;
End;
Te32.dwSize := sizeof(THREADENTRY32);
If Thread32First(ThreadSnap, Te32) = True Then
Begin
Repeat;
If Te32.th32OwnerProcessID = PID Then
Begin
NewThread := OpenThread(THREAD_SUSPEND_RESUME, False, Te32.th32ThreadID);
If F_Pause = True Then
Begin
SuspendThread(NewThread);
End
Else
Begin
ResumeThread(NewThread);
End;
CloseHandle(NewThread);
End;
Until Thread32Next(ThreadSnap, Te32) = False;
Result := True;
End
Else
Begin
Result := False;
End;
CloseHandle(ThreadSnap);
end;
Aufruf:
Delphi-Quellcode:
//Um Prozess zu pausieren:
PauseProcess(2940, True);
//Um Prozess fortzusetzen:
PauseProcess(2940, False);