pradeep,krishna has asked for the wisdom of the Perl Monks concerning the following question:

Hai all fellow monks

I have the following code to close all the opened Remote Desktop Connection windows.

#perl use Win32::GuiTest qw(FindWindowLike MenuSelect WaitWindow WMSetText + PushChildButton GetSystemMenu SetForegroundWindow); @windows = FindWindowLike(0, "Remote Desktop Connection"); for (@windows) #--for each of the open windows do the follow +ing { MenuSelect("&Close", 0, GetSystemMenu($_,FALSE)); }


The main drawback of this code is it closes only the windows at the foreground of my screen, as MenuSelect function works on the window with focus(Foreground)

Help me in solving this.

Thanks in advance :)

Replies are listed 'Best First'.
Re: How to close an application window in Background?
by roboticus (Chancellor) on Mar 20, 2014 at 11:22 UTC

    pradeep,krishna:

    Then use the SetForegroundWindow function to bring each window to the foreground before trying to close the window. You're already specifying the function in your use statement, so use it.

    I find it remarkable that your post shows that you know the existence of the function, and you know that you can't close the window because it's not in the foreground.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Dear friend roboticus
      As i have mentioned its a drawback as it closes only foreground windows, I mean that I want to close the windows in background also(I apologize you as I did not mention this) I don't want to disturb the fore ground windows as i am scheduling my script after converting it to executable file. So as it starts its job in background i want none of the foreground processes to be disturbed.
      Thanks for your valuable time.. :)

Re: How to close an application window in Background? (GuiTest PostMessage)
by Anonymous Monk on Mar 21, 2014 at 04:27 UTC

      Hi Anonymous Monk...

      I tried it.., but i am getting the error saying

      Undefined subroutine &main::WM_KEYDOWN called at login.pl line 33.
      Undefined subroutine &main::WM_KEYUP called at login.pl line 34.

        I tried it.., but i am getting the error saying

        Why don't you define the constants?

Re: How to close an application window in Background?
by Anonymous Monk on Mar 21, 2014 at 12:31 UTC

      Thanks buddy... :)
      Its working...