First-up, I'm running ActiveState perl v5.8.9 under Windows XP SP3 (32-bit) on a fairly reasonable Inter Core2 Duo PC @ 3GHz and with 4GB RAM...

I have an application where a number of instances of an .exe run and they each have different title text on their windows.

I'm trying to work a way that I can capture the window title for each of the instances and if one of the items is missing, I can do something to restart it, viz:

list of jobs = (123, 456, 789) for each running job process if process window title matches one of job list note job number is running go to next process endif endfor for each required job if not flagged as running create the job endif endfor

Now, I can use something like Win32::Process::Info to get some basic info... but not the window title (although, that module seems to be rather unreliable anyway). If I use Win32::API, I can get into GetConsoleTitle() in kernel32.dll and retrieve the window title for my own cmd.exe process... but how do I get the window title for another process?

I can do things a very klunky way and shell out a 'tasklist' command and then parse the results, viz:

c:\>cmd.exe /c "tasklist /v"

Image Name     PID Session Name ...   CPU Time Window Title                                                            
=========== ====== ============ ... ========== ==============...
Socks.exe    10968 Console             0:00:01 2442 - Socks                                                            
Socks.exe     1240 Console             0:00:00 2745 - Socks                                                            
Socks.exe    20720 Console             0:00:01 4085 - Socks                                                            
Socks.exe     6188 Console             0:00:00 2423 - Socks

...but I would think there'd have to be a 'native perl' -way to do it?

I've scoured through CPAN and had a look through the Monks' site but have had no joy.

I would appreciate any thoughts on a 'more elegant' means to approach the problem.

Thanks.

In reply to 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.