Ultimately it depends what kind of program it is. If it's a commandline utility like cmd.exe, you can use a dll like
exec.dll to monitor the output and when it ends (sort of). If it's some GUI application that's a little more difficult.
You *can* do this with COM, there's a script floating around that basically does what exec.dll does without the need of a DLL, but it's the same concept.