By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Lauching an App and using the Exit Code

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Micus" <No**@nowhere.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl
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
Nov 17 '05 #2

P: n/a

"Igor Tandetnik" <it********@mvps.org> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
"Micus" <No**@nowhere.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl
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


Thanks Igor, I'll give it a shot,
M
Nov 17 '05 #3

P: n/a

"Igor Tandetnik" <it********@mvps.org> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
"Micus" <No**@nowhere.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl
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

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.