c++ - CreateProcess 成功,但 GetExitCodeProcess 返回 C0000142

标签 c++ winapi process

我正在尝试使用类似于 this code 的 CreateProcessAsUser() API 从服务启动用户模式进程.我的代码在 99% 的时间里工作正常,除了有时 API 成功,我从 PROCESS_INFORMATION 获取进程句柄。结构,但进程本身没有出现在我打算运行它的交互式用户 session 中。

有趣的是,如果我调用 GetExitCodeProcess () 在进程句柄上它成功返回代码 0xC0000142。知道为什么吗?

最佳答案

错误 0xC0000142 是 STATUS_DLL_INIT_FAILED(我使用 Error Code Lookup Tool 确定了这一点)。快速谷歌发现 this question ,它说:

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,并在成功时使用它(即您有一个有效的窗口 session ),或者在失败时回退到失败模式。

关于c++ - CreateProcess 成功,但 GetExitCodeProcess 返回 C0000142,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13425106/

相关文章:

c++ - 向上转换和重载流运算符

c++ - 如何在启动前为特定应用程序设置 Hook

c++ - 处理 WM_POINTER 消息时如何检测双击/点击?

bash - Linux pgrep 事件 xsession

python - 如何使用 libclang 检索完全限定的函数名称?

c++ - "Cleaning up"嵌套 if 语句

c# - 检测单个 Windows 进程退出事件 C#

iPhone UIActivityIndi​​cator 直到进程完成后才会显示

python - 如何进行视频取景?

c - 将 argv[] 传递给 CreateProcess() 的方法