This code, like this other code also dealing with processes by the same author will kill a Windows Process.
#include <stdio.h>
#include <windows.h>
int main(int argc, char **argv)
{
if(argc < 2)
{
printf("\n\nUsage: killprocess [PID]\n\n");
return 0;
}
DWORD dwPID = atoi(argv[1]);
// Open the process with privileges that let us terminate it.
HANDLE pHandle = OpenProcess(PROCESS_TERMINATE, FALSE, dwPID);
// Poon the process, or try.
if(TerminateProcess(pHandle, 0) != 0)
printf("\n\nProcess terminated successfully.\n\n");
else
printf("\n\nUnable to terminate process.\n\n");
// Close the handle.
CloseHandle(pHandle);
return 0;
}