To answer the original question, to get the process descriptor by its PID and call TerminateProcess, you will need the following code:
BOOL TerminateProcess(DWORD dwProcessId, UINT uExitCode) { DWORD dwDesiredAccess = PROCESS_TERMINATE; BOOL bInheritHandle = FALSE; HANDLE hProcess = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); if (hProcess == NULL) return FALSE; BOOL result = TerminateProcess(hProcess, uExitCode); CloseHandle(hProcess); return result; }
Keep in mind that TerminateProcess does not allow its target to clear and exit in the correct state. Think twice before using it.
Don reba
source share