Best method to (gracefully) quit another application
I'm writing a small launcher that is supposed to mount a virtual drive (a TrueCrypt volume), launch a menu application (called PortableApps) on that volume and then wait until this application quits. Once it does, the launcher also asks all processes launched from the volume to quit as well, waits until they do and then unmounts the volume.
Anyway, I've got this working for the most part. The only thing that doesn't really work very well is the part where it's supposed to quit the other applications. I'm using EnumProcesses/Modules and GetModuleFileNameEx to find all processes launched from the volume. Comparing the results with EnumWindows gives me the window handles of those processes and sending them a WM_CLOSE works for a couple of applications. Others either "ignore" the message or one particular application (FreeCommander) crashes. I'm guessing this is because I send this message to all windows of a process. (Googling for something like a 'mainwindow' didn't yield any helpful results:/)
I was wondering if anybody might have a better idea on how to do this (short of using TerminateProcess :)).