daily pastebin goal
16%
SHARE
TWEET

Kill process [Win32 API] (Option 1)

appo Dec 27th, 2013 365 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <process.h>
  3. #include <Tlhelp32.h>
  4. #include <winbase.h>
  5. #include <string.h>
  6. void killProcessByName(const char *filename)
  7. {
  8.     HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
  9.     PROCESSENTRY32 pEntry;
  10.     pEntry.dwSize = sizeof (pEntry);
  11.     BOOL hRes = Process32First(hSnapShot, &pEntry);
  12.     while (hRes)
  13.     {
  14.         if (strcmp(pEntry.szExeFile, filename) == 0)
  15.         {
  16.             HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,
  17.                                           (DWORD) pEntry.th32ProcessID);
  18.             if (hProcess != NULL)
  19.             {
  20.                 TerminateProcess(hProcess, 9);
  21.                 CloseHandle(hProcess);
  22.             }
  23.         }
  24.         hRes = Process32Next(hSnapShot, &pEntry);
  25.     }
  26.     CloseHandle(hSnapShot);
  27. }
  28. int main()
  29. {
  30.     killProcessByName("notepad++.exe"); //process Name
  31.     return 0;
  32. }
  33.  
  34. // 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