Windows:创建自己的杀死程序

Windows: kill program that creates itself

本文关键字:程序 自己的 创建 Windows      更新时间:2023-10-16

我偶然创建了一个程序,该程序继续自行呼叫createProcess-导致无限循环。

一旦该程序开始运行,我将如何杀死该程序?我试图通过任务管理器杀死这一点,但是由于该程序要求自己开始并立即死亡,因此它继续消失并重新出现在任务管理器中,从而使其"不可阻挡"。

停止此操作的唯一方法似乎是PC的重新启动,这可能非常不便。

int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow )
{    
    using namespace std;    
    CreateProcess( L"self.exe",
                   NULL,            // No command line arguments
                   NULL,            // Process handle not inheritable
                   NULL,            // Thread handle not inheritable
                   NULL,            // Set handle inheritance to NULL
                   NULL,            // No creation flags
                   NULL,            // Use parent's environment block
                   NULL,            // Use parent's starting directory 
                   &lpStartupInfo,  // Pointer to STARTUPINFO structure
                   &lpProcessInfo   // Pointer to PROCESS_INFORMATION structure
                   );
    return 0;
    //return (int)msg.wParam;
}

从最终用户的角度来看,简单的解决方案是按 ctrl alt alt del BD>并注销。如果要使会话保持生命,则像这样的叉炸弹的唯一解决方案就是使用了解过程树的工具。taskkill /T /IM self.exe如评论或Process Explorer中的"杀死过程树"功能。子进程可能仍然能够偷偷摸摸,因此您可能必须多次执行杀死命令。


如果我为此编程了杀戮工具,我将列举这些过程,当发现目标过程时,您打开了一个手柄,并尝试将其与作业对象相关联。工作对象允许您拒绝创建子过程,并可以轻松终止工作中的所有过程。只需致电TerminateProcess如果无法将过程添加到作业中。

您需要在循环中运行此枚举代码,直到您杀死了所有所需的过程。