如果通过ShellExecuteEx成功启动可执行文件后,为什么SHELLEXECUTEINFO.hProcess仍然是NULL,但是如果我使用CreateProcess启动该可执行文件,而将PROCESS_INFORMATION.hProcess设置为正确的可执行文件句柄呢?

我必须使用ShellExecuteEx启动该可执行文件,因为必须对其进行提升。我正在启动的可执行文件是我创建的winMain应用程序。

SHELLEXECUTEINFOW shellExecuteInfo;
memset(&shellExecuteInfo, 0, sizeof(SHELLEXECUTEINFOW));
shellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
shellExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shellExecuteInfo.hwnd = NULL;
shellExecuteInfo.lpFile = pathToExe;
shellExecuteInfo.lpDirectory = NULL;
shellExecuteInfo.nShow = SW_HIDE;
shellExecuteInfo.lpVerb = L"runas";
shellExecuteInfo.hInstApp = NULL;
shellExecuteInfo.lpParameters = NULL;
ShellExecuteExW(&shellExecuteInfo);

最佳答案

因此,问题在于SHELLEXECUTEINFO.lpFile等于指向可执行文件的符号链接的路径。这导致使用动态数据交换。
MSDN说


  在某些情况下,例如通过DDE对话满足执行要求时,将不返回任何句柄。


因此,如果您需要处理该过程,则必须将lpFile设置为可执行文件的实际路径,或者解析符号链接的路径。

使用lpVerb = "runas"进行仰角时,效果很好。

关于c - 为什么ShellExecuteEx不设置SHELLEXECUTEINFO.hProcess的值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39495578/

10-10 03:13