Get PID from ShellExecute

早过忘川 提交于 2019-12-01 07:45:59

问题


I am launching a process from ShellExecuteEx, and I really need to get the ProcessID (It's part of the requirement of this class).

Somehow all the important SHELLEXECUTEINFO returns null. So for example if I use this code:

exInfo.lpVerb = "open";
exInfo.lpFile = "C:\\Windows\\system32\\cmd.exe";
exInfo.nShow  = 5;

ShellExecuteExA(exInfo);

It launched CMD.exe. But now I need to get it's PID. exInfo.hwnd is returning 0, and exInfo.hProcess is returning null. Is this normal behaviour?

I don't really want to resort to using CreateProcess(), because my function should also be able to launch documents like "C:\doc1.docx". This is just a method, in which I cannot predict what is going to be launched (So I cannot know the window title/classname from beforehand, get the hWnd from there and then get the PID).

Could somebody kindly point out my mistake? Thanks.


回答1:


You need to set a flag (SEE_MASK_NOCLOSEPROCESS) in exInfo.fMask



来源:https://stackoverflow.com/questions/7620322/get-pid-from-shellexecute

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