Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <windows.h>
  2. #include <process.h>
  3. #include <Tlhelp32.h>
  4. #include <winbase.h>
  5. #include <string.h>
  6.  
  7. void killProcessByName(const char *filename)
  8. {
  9. HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
  10. PROCESSENTRY32 pEntry;
  11. pEntry.dwSize = sizeof(pEntry);
  12. BOOL hRes = Process32First(hSnapShot, &pEntry);
  13. while (hRes)
  14. {
  15. if (strcmp(pEntry.szExeFile, filename) == 0)
  16. {
  17. HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0, (DWORD)pEntry.th32ProcessID);
  18.  
  19. if (hProcess != NULL)
  20. {
  21. TerminateProcess(hProcess, 9);
  22. CloseHandle(hProcess);
  23. }
  24. }
  25.  
  26. hRes = Process32Next(hSnapShot, &pEntry);
  27. }
  28.  
  29. CloseHandle(hSnapShot);
  30. }
  31.  
  32. int main()
  33. {
  34. killProcessByName("notepad.exe");
  35. system("pause");
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement