Closing a CreateProcess() DOS box

Running on Windows 9.x I need to provide my user with the capability to execute a program of their choice when they hit the F10 key. It may be a Windows program, or a DOS program or a DOS batch file. They choose. I am using CreateProcess() to execute a command line that they provide.

My problem is that if it is a DOS program or batch file the DOS box stays open even after the program ends.

I know that:
1) Putting "Exit" as the last statement in a DOS batch file does NOT work, so please don't suggest that.

2) Using COMMAND.COM /c "user program.exe" supposedly works, but "user program.exe" may be a Windows program, so I can't do that either.

Certainly with all the options available in CreateProcess() there must be a way of closing the Window when the DOS program ends! Isn't there??

Or is there some ugly way (using GetProcessTimes() or something else) to decide that the program has ended and then kill it with TerminateProcess()?

Thanks,
NC
nchenkinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ufolk123Commented:
One solution is that you identify the type of EXE before running it using CreateProcess.

By reading the first few bytes of file you can identify that whether it is a windows exe or dos exe.Depending on this result you can either pass it directly to CreateProcess or use COMMAND.COM syntex.

You can get more information about EXE file header structure from MSDN site.

If you want more details please get back.



0
jkrCommented:
Decoding the EXE header is overkill - 'SHGetFileInfo()' using 'SHGFI_EXETYPE' will do it...
0
nchenkinAuthor Commented:
Hmmm...

This is unfortunate.

ufolk123 started to turn me in the right direction, but jkr really had the answer.

Too bad I can't split the points 50/50.

But I guess they should go to jkr since elegance counts. I wasn't aware of SHGetFileInfo() (a Windows newbie I am) but that one line of code does what I need.

So, jkr its yours.

NC
0
jkrCommented:
Thanx, nchenkin!

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nchenkinAuthor Commented:
jkr,

My pleasure.

I just tested it, works like a charm.

Thanks,
NC
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.