#perl use constant WM_KEYDOWN => 0x0100; use constant WM_KEYUP => 0x0101; use Win32::GuiTest qw(FindWindowLike MenuSelect WaitWindow WMSetText PushChildButton GetSystemMenu SetForegroundWindow); system('"start %windir%\system32\mstsc.exe"'); #--System program to open the the Remote Desktop Connection application sleep(2); #let me see the window $max_Sleep_time=5; #--Maximum wait in sec to open the Remote Desktop Connection application WaitWindow("Remote Desktop Connection",$max_Sleep_time); @windows = FindWindowLike(0, "Remote Desktop Connection"); for (@windows) #--for each of the open windows do the following { #--MenuSelect("&Close", 0, GetSystemMenu($_,FALSE)); hwndSendKeys($_,"%{F4}") } sub hwndSendKeys { my ( $hwnd, $keys, $delay) = @_; $delay = 25 unless defined $delay; $delay /= 1000; my @k = Win32::GuiTest::parse_keys($keys); for ( my $i = 0; $i < @k; $i+=2) { if ( defined $k[$i]) { Win32::GuiTest::DbgShow("SendRawKey(@k[$i,$i+1])\n"); #~ Win32::GuiTest::SendRawKey( @k[$i,$i+1]); my( $key, $updown ) = @k[ $i, $i+1 ] ; my $wmupdown = WM_KEYDOWN(); $wmupdown = WM_KEYUP() if $updown == 2; Win32::GuiTest::PostMessage( $hwnd, $wmupdown, $key , 0 ); select(undef,undef,undef,$delay); ## deprecated $i+=2; ### SUPER BROKEN otherwise DOUBLING bug } else { $k[$i+1]-> (); } } }