how to get return value of an exe called by ShellExecute
24,785
Use ShellExecuteEx
instead to get the process handle, and GetExitCodeProcess
to get the exit code.
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);
Author by
2vision2
Updated on February 12, 2020Comments
-
2vision2 over 4 years
How to get the return value of an exe which is called by shellexecute function.
ShellExecute(NULL, NULL, TEXT ( ".\\dpinstx86.exe" ), NULL, NULL, SW_SHOWNORMAL);
In the above example I want the return value of "dpinstx86.exe".
-
user1703401 about 12 yearsDon't forget to wait on the handle.
-
kol about 12 yearscodeproject.com/Articles/1842/… ...and call GetExitCodeProcess() with the hProcess member of SHELLEXECUTEINFO.
-
2vision2 about 12 yearsDear Kol, Does the GetExitProcess returns the error code of the exe I'm calling in "ShellExecuteEx"?? i.e., does "lpExitCode" the second parameter of "GetExitProcess" contains the return value of "dpinst.exe" as per my example...and do I want to wait for the shellexecuteEx to complete?
-
Ben over 11 years@Hans - for clarification, wait meaning
WaitForSingleObject()
, I hope (new to this so please correct me if I'm wrong...) -
David Heffernan over 8 yearsYou also leak the handle. Close it after you've waited on it. You also fail to check for errors. CreateProcess is a much better choice.