(Also, see the next iteration.)
I have this small program for terminating processes via their respective process image names (.exe
files):
#include <stdio.h>
#include <windows.h>
#include <TlHelp32.h>
int main(int argc, char* argv[]) {
if (argc != 2) {
puts("processkiller.exe PROCESS_NAME");
return EXIT_SUCCESS;
}
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE) {
while (Process32Next(snapshot, &entry) == TRUE) {
if (strcmp(entry.szExeFile, argv[1]) == 0) {
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,
FALSE,
entry.th32ProcessID);
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
}
CloseHandle(snapshot);
return EXIT_SUCCESS;
}
Note that you need to run processkiller.exe
in administrator mode in order to actually terminate the requested processes.
Critique request
Please tell me anything that comes to mind.