CreateProcess succeeds, but GetExitCodeProcess returns C0000142(CreateProcess 成功,但 GetExitCodeProcess 返回 C0000142)
问题描述
我正在尝试使用类似于 此代码.我的代码在 99% 的情况下工作正常,除了 API 成功的时候,我从 PROCESS_INFORMATION 结构,但进程本身没有出现在我打算运行的交互式用户会话中.
I'm trying to start a user-mode process from a service using CreateProcessAsUser() API similar to this code. My code works fine in 99% of the time, except at times that API succeeds, I get the process handle from the PROCESS_INFORMATION struct but the process itself doesn't appear in the interactive user session that I was intending it to run in.
有趣的是,如果我调用 GetExitCodeProcess() 在进程句柄上成功并返回代码 0xC0000142.知道为什么吗?
The interesting thing is that if I call GetExitCodeProcess() on the process handle it succeeds with return code 0xC0000142. Any idea why?
推荐答案
Error 0xC0000142 is STATUS_DLL_INIT_FAILED
(我使用 错误代码查找工具).一个快速的谷歌发现 这个问题,其中说:
Error 0xC0000142 is STATUS_DLL_INIT_FAILED
(I determined this using the Error Code Lookup Tool). A quick google found this question, which says:
此问题的最常见原因是链接到 user32.dll
的程序在无法与系统的窗口站和桌面对话的上下文中运行.通常,诸如代理之类的服务在其自己的窗口站和桌面中运行,并且 user32 程序运行良好,但是任何显示对话框的程序都会挂起,而人们没有机会看到错误消息或关闭对话框.
The most common cause of this problem is that a program that links to
user32.dll
was run in a context in which it could not talk to the system's window station and desktop. Normally, a service such as the agent runs in its own window station and desktop, and user32 programs run fine, but any program that displayed a dialog box would then hang without any opportunity for a human being to see the error message or close the dialog.
因此,如果您没有使用 user32.dll
中的任何函数,您应该删除该依赖项.如果您正在使用该 DLL,那么我不确定您应该做什么.一种选择是使用 LoadLibrary
动态加载 DLL,并在成功时使用它(即您有一个有效的窗口会话),或者在失败时回退到失败模式.
So, if you're not using any functions from user32.dll
, you should remove that dependency. If you are using that DLL, then I'm not really sure what you're supposed to do. One option would be to load the DLL dynamically with LoadLibrary
and use it if it succeeds (i.e. you have a valid window session) or to fallback on a failure mode if it fails.
这篇关于CreateProcess 成功,但 GetExitCodeProcess 返回 C0000142的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CreateProcess 成功,但 GetExitCodeProcess 返回 C0000142


基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01