Lauching an App and using the Exit Code

I

Igor Tandetnik

Micus said:
I need to execute 2 applications from an application or batch
file. The first app launched has the user enter a product key and the
app's exit code will be 0 (failed) or 1 (succeeded). Based on the
exit code of the first app, the second app will be run.

Using ShellExecuteEx() does not return the exit code of the
first app.

Use SEE_MASK_NOCLOSEPROCESS flag, and you will get an hProcess HANDLE to
the new process. Wait for the process to terminate with
WaitForSingleObject, then obtain its exit code with GetExitCodeProcess.
Don't forget to call CloseHandle on your handle.

Or you can use CreateProcess instead of ShellExecuteEx, then proceed as
above. Remember that in this case, you get back two handles (for the
process and for the main thread of that process), both of which you need
to close.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
 
M

Micus

Greetings,

I need to execute 2 applications from an application or batch file. The
first app launched has the user enter a product key and the app's exit code
will be 0 (failed) or 1 (succeeded). Based on the exit code of the first
app, the second app will be run.

My problems :

Using a batch file to launch the applications produces an
unattractive command prompt window in the background. I need this to look
pretty. The benefit of using a batch file is that logic based on the exit
code of the first app can be written (errorlevel variable).

Using the system() method to launch the application produces the
command prompt window and does not return the exit code.

Using ShellExecuteEx() does not return the exit code of the first
app.

If anyone knows how to minimize the command prompt window from within a
batch file or how to obtain the exit code of an application launched from
within another application, it would be super. Any other suggestions are
welcome.

TIA,
M
 
M

Micus

Igor Tandetnik said:
Use SEE_MASK_NOCLOSEPROCESS flag, and you will get an hProcess HANDLE to
the new process. Wait for the process to terminate with
WaitForSingleObject, then obtain its exit code with GetExitCodeProcess.
Don't forget to call CloseHandle on your handle.

Or you can use CreateProcess instead of ShellExecuteEx, then proceed as
above. Remember that in this case, you get back two handles (for the
process and for the main thread of that process), both of which you need
to close.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925

Thanks Igor, I'll give it a shot,
M
 
M

Micus

Igor Tandetnik said:
Use SEE_MASK_NOCLOSEPROCESS flag, and you will get an hProcess HANDLE to
the new process. Wait for the process to terminate with
WaitForSingleObject, then obtain its exit code with GetExitCodeProcess.
Don't forget to call CloseHandle on your handle.

Or you can use CreateProcess instead of ShellExecuteEx, then proceed as
above. Remember that in this case, you get back two handles (for the
process and for the main thread of that process), both of which you need
to close.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top