开发者

Get PID from ShellExecute

开发者 https://www.devze.com 2023-04-10 13:43 出处:网络
I am launching a process from ShellExecuteEx, and I really need to get the ProcessID (It\'s part of the requirement of this class).

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号