daily pastebin goal
91%
SHARE
TWEET

Kill process (Option 1)

appo Dec 27th, 2013 341 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. program Project1;
  2. {$APPTYPE CONSOLE}        //  remove {$ APPTYPE CONSOLE} to hide it
  3.  
  4. {$R *.res}
  5. uses
  6.   Tlhelp32,
  7.   Windows,
  8.   SysUtils;
  9.  
  10. function KillTask(ExeFileName: string): integer;
  11. const
  12.   PROCESS_TERMINATE=$0001;
  13. var
  14.   ContinueLoop: BOOL;
  15.   FSnapshotHandle: THandle;
  16.   FProcessEntry32: TProcessEntry32;
  17. begin
  18.   result := 0;
  19.  
  20.   FSnapshotHandle := CreateToolhelp32Snapshot
  21.                      (TH32CS_SNAPPROCESS, 0);
  22.   FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
  23.   ContinueLoop := Process32First(FSnapshotHandle,
  24.                                  FProcessEntry32);
  25.  
  26.   while integer(ContinueLoop) <> 0 do
  27.   begin
  28.     if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
  29.          UpperCase(ExeFileName))
  30.      or (UpperCase(FProcessEntry32.szExeFile) =
  31.          UpperCase(ExeFileName))) then
  32.       Result := Integer(TerminateProcess(OpenProcess(
  33.                         PROCESS_TERMINATE, BOOL(0),
  34.                         FProcessEntry32.th32ProcessID), 0));
  35.     ContinueLoop := Process32Next(FSnapshotHandle,
  36.                                   FProcessEntry32);
  37.   end;
  38.  
  39.   CloseHandle(FSnapshotHandle);
  40. end;
  41. begin
  42.   try
  43.     KillTask('skype.exe'); //process Name
  44.   except
  45.     on E: Exception do
  46.       Writeln(E.ClassName, ': ', E.Message);
  47.   end;
  48. end.
  49.  
  50. // Coded by Appo //
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top