Anfidya'nın arka bahçesi..

There is dark web in the deep web..

[Delphi] Programı Suspend ve Resume Etme(Durdur&Çalıştır)

leave a comment

Merhaba,

Aşağıdaki kodlar ile herhangi bir işlemi pid numarası ile durdurabilir ve tekrar aktif edebiliriz.

Uses:

ShlObj,ShFolder,ShellAPi, ImageHlp, messages, TLHelp32, psAPI;

Kod kısmımız:

 const
 THREAD_TERMINATE = ($0001);
 THREAD_SUSPEND_RESUME = ($0002);
 THREAD_GET_CONTEXT = ($0008);
 THREAD_SET_CONTEXT = ($0010);
 THREAD_SET_INFORMATION = ($0020);
 THREAD_QUERY_INFORMATION = ($0040);
 THREAD_SET_THREAD_TOKEN = ($0080);
 THREAD_IMPERSONATE = ($0100);
 THREAD_DIRECT_IMPERSONATION = ($0200);
 THREAD_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $3FF);
procedure PauseProcess(Pid: integer);
 var
 Thread32: TThreadEntry32;
 ThreadSnapshot: THandle;
 ThreadHandle: THandle;
 begin
 ThreadSnapshot := CreateToolHelp32SnapShot(TH32CS_SNAPTHREAD, Pid);
 Thread32.dwSize := SizeOf(TThreadEntry32);
 Thread32First(ThreadSnapshot, Thread32);
 repeat
 if Thread32.th32OwnerProcessID = Pid then begin
 ThreadHandle := OpenThread(THREAD_ALL_ACCESS,False,Thread32.th32ThreadID);
 SuspendThread(ThreadHandle);
 CloseHandle(ThreadHandle);
 end;
 until not (Thread32Next(ThreadSnapshot, Thread32));
 CloseHandle(ThreadSnapshot);
 end;
procedure ResumeProcess(Pid: integer);
 var
 Thread32: TThreadEntry32;
 ThreadSnapshot: THandle;
 ThreadHandle: THandle;
 begin
 ThreadSnapshot := CreateToolHelp32SnapShot(TH32CS_SNAPTHREAD, Pid);
 Thread32.dwSize := SizeOf(TThreadEntry32);
 Thread32First(ThreadSnapshot, Thread32);
 repeat
 if Thread32.th32OwnerProcessID = Pid then begin
 ThreadHandle := OpenThread(THREAD_ALL_ACCESS,False,Thread32.th32ThreadID);
 ResumeThread(ThreadHandle);
 CloseHandle(ThreadHandle);
 end;
 until not (Thread32Next(ThreadSnapshot, Thread32));
 CloseHandle(ThreadSnapshot);
 end;

Written by anfidya

Eylül 25th, 2014 at 1:32 am

Posted in Delphi

Tagged with

Leave a Reply

*