If all the applications you're trying to terminate have a message queue, then sending them a WM_CLOSE or WM_QUIT message as bart has suggested may solve your problem, assuming they don't do anything nasty like only actioning that message, if they generated it.
However, many GUI apps respond to that message by popping up one of those eternally annoying "Do you really want to do what you just said you want to do?" dialog boxes. So then you'll be in the game of having to wait for the dialog to appear, track it down and send it a button push (see Win32::GuiTest ), to dismiss the dialog. (Or waiting for a user to do it and hoping that they don't choose to ignore you or just go home).
But if any of them do not have a message queue, ie. most command line applications, then you're out of luck.
Win32 perl scripts do have a message queue and they do respond to the two messages above as a part of the opcode dispatch loop (win32_async_check()). However, they translate them into a SIGHUP. I'm not sure if that is trappable under win32 using a %SIG handler--I've never had occasion to try it--but if it is, the script could choose to ignore your request.
Of course, if you are writing the applications you want to terminate/replace, then you can use the above information to ensure that next time your applications do the right thing and save their state and terminate when requested to do so. But that won't help you this time.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|