• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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
0
nchenkin
Asked:
nchenkin
  • 2
  • 2
1 Solution
 
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
 
nchenkinAuthor Commented:
jkr,

My pleasure.

I just tested it, works like a charm.

Thanks,
NC
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now