CreateProcess succeeds, but GetExitCodeProcess returns C0000142

。_饼干妹妹 提交于 2019-12-18 02:49:07

问题


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.

The interesting thing is that if I call GetExitCodeProcess() on the process handle it succeeds with return code 0xC0000142. Any idea why?


回答1:


Error 0xC0000142 is STATUS_DLL_INIT_FAILED (I determined this using the Error Code Lookup Tool). A quick google found this question, which says:

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.

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.




回答2:


The CreateProcess...() APIs will return TRUE if they can successfully create the internal process object and begin initialization; they don't wait for the process to load and begin running its executable image. In some cases the initialization later fails, but from the kernel's perspective it was still a successful process creation.



来源:https://stackoverflow.com/questions/13425106/createprocess-succeeds-but-getexitcodeprocess-returns-c0000142

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!