简体   繁体   English

没有新进程,在 CreateProcess 成功启动后

[英]No new process, after succeede launch of CreateProcess

I am trying to create program that will monitor the execution of another process.我正在尝试创建将监视另一个进程的执行的程序。 If the process crashes, my program would restart it.如果进程崩溃,我的程序将重新启动它。 (Kinda process monitor). (有点过程监视器)。 I have main class called ProcessController.我有称为 ProcessController 的主要 class。 There's ProcessController::Start() method that should start the new process.有应该启动新进程的 ProcessController::Start() 方法。 There's code:有代码:

ProcessController::Start()
{

        if (!CreateProcess(
            m_progPath.c_str(),           //Program name
            NULL,        // Command line
            NULL,           // Process handle not inheritable
            NULL,           // Thread handle not inheritable
            FALSE,          // Set handle inheritance to FALSE
            0,              // No creation flags
            NULL,           // Use parent's environment block
            NULL,           // Use parent's starting directory 
            &m_si,            // Pointer to STARTUPINFO structure
            &m_pi)           // Pointer to PROCESS_INFORMATION structure
            )
        {
            printf("CreateProcess failed (%d).\n", GetLastError());
            return false;
        }

        ... other code

}

I never see error code, so CreateProcess executes well, however, no new procees appear (can't see new process in task manager and no windows appears. The app I'm trying to launch also writes logs, but no new logs after I ran my ProcessController.) Permissions of the process I'm trying to launch are set to enable execute it.我从来没有看到错误代码,所以 CreateProcess 执行得很好,但是,没有新进程出现(在任务管理器中看不到新进程,也没有出现 windows。我尝试启动的应用程序也写入日志,但在我之后没有新日志运行我的 ProcessController。)我尝试启动的进程的权限设置为启用执行它。 If I am trying to create notepad++ process using my code, it works fine.如果我尝试使用我的代码创建记事本++ 进程,它工作正常。 The notepad++ window appears. notepad++ window 出现。 I always use full path to the program I am trying to start with my controller.我总是使用我试图从我的 controller 开始的程序的完整路径。

Am I doing something wrong??难道我做错了什么??

Infer that it is a problem with the components to be loaded.推断是要加载的组件有问题。 As mentioned above, if a required DLL cannot be located or fails to initialize, the process is terminated.如上所述,如果找不到所需的 DLL 或无法初始化,则终止该过程。 Also, if the thread is the only active thread in the process, the process is terminated.此外,如果线程是进程中唯一的活动线程,则终止进程。 Loading components failed may cause only active thread in the process.加载组件失败可能会导致进程中只有活动线程。 The following are reference documents: https://learn.microsoft.com/en-us/windows/win32/procthread/terminating-a-thread You can use cmd or anything else to run your compiled exe.以下是参考文档: https://learn.microsoft.com/en-us/windows/win32/procthread/terminating-a-thread您可以使用 cmd 或其他任何东西来运行您编译的 exe。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM