#!/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

In reply to Re^2: How to Retrieve another Process' Window Title? by Anonymous Monk
in thread How to Retrieve another Process' Window Title? by ozboomer

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.