CreateProcess成功,但GetExitCodeProcess返回C0000142 [英] CreateProcess succeeds, but GetExitCodeProcess returns C0000142

查看:1411
本文介绍了CreateProcess成功,但GetExitCodeProcess返回C0000142的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从服务使用CreateProcessAsUser()API启动用户模式进程,类似于此代码。我的代码在99%的时间正常工作,除非有时成功,我得到的处理句柄从 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?

推荐答案

错误0xC0000142是 STATUS_DLL_INIT_FAILED 使用错误代码查找工具)。快速找到Google 这个问题,它说:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆