Running a DOS app from Delphi 4 and closing it afterwards

Hi everybody,

I want to run a DOS application from a Delphi program. This is not the
problem; I know how to do this in a couple of different ways. The
problem is that the DOS box stays open afterwards. Naturally I want to
close the box with the application. But how?!

So far I've thought of two different solutions:

1) Send a "Alt-F4" -- or equivalent -- to the offending DOS box.
2) Instead of calling the DOS app directly I construct a PIF-file
"pointing at it" and somehow use the fact that you can set a checkmark
in the "close on program-end" field. I then call the PIF-file and when
the user terminates the DOS app Windows will automatically close the DOS
box as well.

As 1) goes, I have no idea on how to do this. How do I identify the DOS
box (amongst the others that may exist) and how do I send the "Close
window" message to it?

On 2), I know how to make a PIF-file from scratch but I don't know how
to set the "close on program-end" checkmark.

Thanks in advance for any advice.