Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Killing an Application in Windows NT

by Anonymous Monk
on Dec 17, 2003 at 21:23 UTC ( #315388=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for a way to kill an application in Windows NT. I found the code for killing a process, but this kills more than I want.

Here is my underlying problem: I'm running an application in batch. Because my flexlm license is about to expire, the application sends out a warning message window. When running the application interactively it is a simple thing to just click on the OK button and procede. However, when I'm running in batch it can't always be at my computer to do that, which means my job hangs. My batch job calls this application several times with different input files, so I need to keep killing the warning message about every 15 minutes. So I'm wanting to write a simple program that will look for the application that displays the warning message and kill it if it exists. I can then put this program in the scheduled tasks and just have it look every minute or so. My basic problem is that I don't know the Win32 system calls to obtain the applications list and to kill the application. I assume it is similar to obtaining and killing a process.

Any assistance in this regard would be greatly apprecaited.

the rookie

Comment on Killing an Application in Windows NT
Re: Killing an Application in Windows NT
by BrowserUk (Pope) on Dec 17, 2003 at 21:49 UTC

    The problem is that the pop up window is almost certainly not a separate application (or process), but an integral part of the same application. If you were to detect the process id/handle for the task controlling the popup window and kill it, you would be killing the program that produces it, and your overall process would not complete correctly.

    That leaves you with two options. Re-licence the application or write a program that 'clicks' the appropriate button on the popup window to cause it to be dismissed.

    The former is probably the easiest solution and long term, the right one unless you can find an alternative to it that performs the same job.

    The second, is more complicated, but could be done using perl. A good place to start would be Win32::CtrlGUI which will allow your script to look for the specific popup window, and then 'send' a keystroke or mouse click to it. However, working out how to determine which window to look for, and what and where to send the keystroke(s) or mouse clicks to is non-trivial and not something that anyone here could really help you with much unless they had a copy of the same application.

    You'll need to read the documentation to the module quite carefully.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!

      Similar to the doctor responding to the woman who says "My arm hurts when I do this..", the simple answer is to renew your FlexLM licenses, but this is hardly instructive. Fortunately, it looks like other Monks have provided some wisdom in this area.
      I have to also recommend proper licensing for the application you have (presumably) agreed to use under the author's terms.

      As previously mentioned, a window and a process are not the same thing. and you're really looking to control the window, not the app that generated it.

      I have done some Win32 hacking along these lines, and the specific thing you're looking for is a "Window Handle", usually called (in Windows API docs) hWnd. There is a Win32 API call to find a window's handle, given its name. The title of the message window hopefully doesn't change from run to run, so you can use that to get a handle on the window. From there you have a few choices, depending on what you have Perl modules for:

      1. You could send the window a 'close' message
      2. You could find the handle for the (probably) only button on the window and send it a 'click' message
      3. You could ask the window for its position on the screen, and then move the mouse to the appropriate offset from that position; then click the mouse. I think the Win32::CtrlGUI module mentioned above can do this.

      --
      Spring: Forces, Coiled Again!

        Um. It makes more sense to respond to the original post rather than to a reply that has already said the same things you are saying?


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        Hooray!

Re: Killing an Application in Windows NT
by ant9000 (Monk) on Dec 18, 2003 at 08:33 UTC
    You could try out cmdow: it's small and efficient.
    Not a Perl solution, but then, don't we all think that TMTOWTDI?
    HTH,
    Ant9000
Re: Killing an Application in Windows NT
by msemtd (Scribe) on Dec 18, 2003 at 09:00 UTC
    This beastie has all you need for the problem described.
    use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow + SendKeys);
      Thank you! I will check this out.
Re: Killing an Application in Windows NT
by RolandGunslinger (Curate) on Dec 18, 2003 at 14:11 UTC
    Look at Win32::PerfLib for retrieving the task list, with this information you'll get the pid and pname, you could then do a system("kill $pid") to kill the rogue process. Check out cpan.org for the perl module to do this.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://315388]
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-07-25 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (174 votes), past polls