how to Ensure exe launch using ShellExecuteEx
I have a EXE1 which requires an Config file when launched.
I am using Sh开发者_Python百科ellExecuteEx to launch EXE1 from EXE2.
It is working fine as such but the if the config file is not preset for EXE1 then it do not get launched however ShellExecuteEx returns TRUE(1) .
I am checking the return value of ShellExecuteEx to Disable the "Launch" BUtton in EXE2 which launch the EXE1.Since ShellExecuteEx returns TRUE(1) so Launch button is Disable which wrong functionality.
I tried this with CreateProcess as well, it also behaves in the same way.
How can I Ensure exe is launched or not.
You would have to signal from the second program into the first program in some way -- by using shared memory, mutants, or some other interprocess communication method.
ShellExecuteEx only cares about whether the executable is able to start, not whether it's able to do what you expected it to.
Alternately, use CreateProcess instead and monitor for the return code of the child process.
ShellExecuteEx
returns true if it's able to launch the executable. It does not actually convey the return code from the launched application.
You can use WaitForSingleObject to wait for few milliseconds on the launched application's handle (hProcess
) in SHELLEXECUTEINFO
struct. If WaitForSingleObject
returns WAIT_OBJECT_0
or WAIT_ABANDONED
, you can 'assume' that the launched application has exited. If the launched application continues to run, then your wait would timeout. However, this is not a foolproof method. A more robust way would be to have some IPC mechanism like pipe between applications.
精彩评论