timus221

Untitled

Mar 4th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 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. 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");
  31. return 0;
  32. }
Add Comment
Please, Sign In to add comment