in reply to Re: How to Retrieve another Process' Window Title?
in thread How to Retrieve another Process' Window Title?
#!/usr/bin/perl -- use strict; use warnings; use Win32::Process qw/ NORMAL_PRIORITY_CLASS CREATE_NEW_CONSOLE /; use Win32::GuiTest qw/ IsWindowVisible IsWindowEnabled FindWindowLike GetWindowText GetClassName GetChildDepth GetDesktopWindow WaitWindow /; use Win32::API; $Win32::GuiTest::debug = @ARGV; exit Fafafa(); BEGIN { Win32::API::->Import("user32","DWORD GetWindowThreadProcessId( HWN +D hWnd, LPDWORD lpdwProcessId)") or die $^E; sub TidPid { my $pid = pack 'L!',0 ; my $tid = GetWindowThreadProcessId($_[0], $pid); $pid = unpack 'L!', $pid; return $tid, $pid ; } sub Tid { ( TidPid(@_))[0] } sub Pid { ( TidPid(@_))[1] } } sub ErrorReport { print Win32::FormatMessage( Win32::GetLastError() ); } sub Fafafa { my %cmd; for( 1 .. 3 ){ Win32::Process::Create( my $cmdp, "$ENV{WINDIR}\\system32\\cmd.exe", "/K title $_ - Socks", 0,# don't inherit nothing NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, '.' ) or die ErrorReport(); $cmd{ $cmdp->GetProcessID } = $cmdp; } print "pid $$\n"; print "sleep 1, so the GUIs come up\n"; for(1..3){ WaitWindow("$_ - Socks"); } # too fast, so sleep after +wards sleep 1; #~ for( FindWindowLike(undef,' - Socks','ConsoleWindowClass') ){ for (FindWindowLike((undef) x 4, 1)) { next unless IsWindowEnabled($_) or IsWindowVisible($_); next unless $cmd{ Pid( $_ ) }; # the parent is us printf "0x%08X (%8d) %8d/%8d %-30s '%s'\n", $_, $_, TidPid($_), GetClassName($_), GetWindowText($_) ; } for ( values %cmd ){ printf "Killing %d\n", $_->GetProcessID(); $_->Kill(0); } 0; } __END__ pid 1204 sleep 1, so the GUIs come up 0x002403D0 ( 2360272) 1888/ 1684 ConsoleWindowClass + '3 - Socks' 0x002003B8 ( 2098104) 1496/ 1992 ConsoleWindowClass + '2 - Socks' 0x002B0384 ( 2818948) 1412/ 1692 ConsoleWindowClass + '1 - Socks' Killing 1684 Killing 1692 Killing 1992
|
|---|