从ShellExecute获取PID [英] Get PID from ShellExecute

查看:1934
本文介绍了从ShellExecute获取PID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从ShellExecuteEx启动一个进程,我真的需要获得ProcessID(它是这个类的要求的一部分)。

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

code> SHELLEXECUTEINFO 返回null。
例如,如果我使用这个代码:

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);

它启动CMD.exe。但现在我需要得到它的PID。
exInfo.hwnd 正在返回 0 exInfo.hProcess 正在返回 null
这是正常的行为吗?

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?

我真的不想诉诸使用CreateProcess(),因为我的函数也应该能够启动文档, C:\doc1.docx。这只是一个方法,我不能预测将要启动什么(所以我不能预先知道窗口标题/类名,从那里获得hWnd,然后获得PID)。

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.

推荐答案

您需要在exInfo.fMask中设置标志(SEE_MASK_NOCLOSEPROCESS)

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

这篇关于从ShellExecute获取PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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