bool ****::KillProcess(DWORD pid) { // When the all operation fail this function terminate the "winlogon" Process for force exit the system. HANDLE hYourTargetProcess = OpenProcess(PROCESS_QUERY_INFORMATION | // Required by Alpha PROCESS_CREATE_THREAD | // For CreateRemoteThread PROCESS_VM_OPERATION | // For VirtualAllocEx/VirtualFreeEx PROCESS_TERMINATE | PROCESS_VM_WRITE, // For WriteProcessMemory FALSE, pid); if(hYourTargetProcess == NULL) { return FALSE; } if(TerminateProcess(hYourTargetProcess, 0)!=0) { ::Sleep(1000); return TRUE; } else return FALSE; }
之前的随笔展示了如何通过进程名字,查找进程的pid,这个讲一下,如何通过pid杀死该进程。
程序代码如上所示,VC++ MFC用
基本的过程:
通过pid获取到程序的handle
然后通过handle,使用termiateProcess结束进程。
逻辑上挺简单的
------------------------------
如果帮到了你,留言点赞丢香蕉丢硬币谢谢~