C++ 如何获取ShellExecute调用的exe的返回值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10896778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:35:38  来源:igfitidea点击:

how to get return value of an exe called by ShellExecute

c++capiwinapishellexecute

提问by 2vision2

How to get the return value of an exe which is called by shellexecute function.

如何获取shellexecute函数调用的exe的返回值。

ShellExecute(NULL, NULL, TEXT ( ".\dpinstx86.exe" ), NULL, NULL, SW_SHOWNORMAL);

In the above example I want the return value of "dpinstx86.exe".

在上面的例子中,我想要“dpinstx86.exe”的返回值。

回答by kol

Use ShellExecuteExinstead to get the process handle, and GetExitCodeProcessto get the exit code.

使用ShellExecuteEx来获取进程句柄,并GetExitCodeProcess获取退出代码。

SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\MyProgram.exe";        
ShExecInfo.lpParameters = "";   
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL; 
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);