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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: 'Gracefully' closing a win32 app by BrowserUk
in thread 'Gracefully' closing a win32 app by ethrbunny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.