in reply to How to Retrieve another Process' Window Title?

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).

How is it unreliable?

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

Why? If Win32::Process::Info is not native, is Win32::GuiTest 'native'? Win32::OLE?

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

?node_id=3989;HIT=title;re=N
How To Read Win32 Window Title Text
How can I fetch text from Windows Title Bars?

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

:) Thats one of those in the eye of the beholder deals, my definition: does it do what I want? does it save me work?

  • Comment on Re: How to Retrieve another Process' Window Title?

Replies are listed 'Best First'.
Re^2: How to Retrieve another Process' Window Title?
by ozboomer (Friar) on Feb 07, 2011 at 03:04 UTC

    I'll admit I haven't used the Win32::Process::Info before today but consider the following code:

    use Win32::Process::Info my $st = Win32::Process::Info->import('NT', 'WMI'); my $pi = Win32::Process::Info->new (undef, 'WMI'); my @pids = $pi->ListPids (); my @info = $pi->GetProcInfo (); for my $prc (@info){ printf("%s, %s, %s\n", $prc->{"ProcessId"}, $prc->{"Name"}, $prc->{"Description"} ); }

    When run, this code will make the cmd.exe session variously: a) run without error; b) fail with a "...has encountered a problem and needs to close..." dialog being shown; c) fail with a "The memory could not be 'read'." dialog being shown; d) hang until I terminate the perl.exe image manually with Task Manager. This appears, at least, not very robust to me.

    Re: a 'native' way.. I tend to think if there's some CLI utility that produces some sort of useful output, there has to be a way that Perl can do the same (providing someone has built-up a module)... or at least if it's something that's managed/controlled by Windows, I should be able to call Windows to do my job for me, rather than starting from scratch; I just have this thing that I don't like to 'shell' to the OS -- it just seems to be like "giving-up" or something...(!)

    ...and I guess my queries in the Supersearch were lacking, 'coz somehow I didn't catch those Monks' site nodes, thanks.

    I'll go and see if I can decipher the intricacies of Win32::GuiTest and Win32::API::Callback...

      You say:

      I just have this thing that I don't like to 'shell' to the OS -- it just seems to be like "giving-up" or something...(!)

      After just having said:

      I should be able to call Windows to do my job for me,

      Run this:

      tasklist /nh /v | perl -nle"@a=unpack'A29A5A123A*',$_; print join'|',@ +a[1,3]"

      That's Windows "doing your job for you".


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      This appears, at least, not very robust to me.

      What versions of each are you running? (perl , os, modules/Devel::Modlist)

                What versions of each are you running? (perl , os, modules/Devel::Modlist)

        As I mentioned at the start of my posting:-

               I'm running ActiveState perl v5.8.9 under Windows XP SP3 (32-bit)

        ...cmd.exe reports WinXP as Version 5.1.2600... and Win32::Process::Info is at 1.016.

            What versions of each are you running? (perl , os, modules/Devel::Modlist)

        Apologies for not understanding what was requested. Here's the output you were asking about:-

        c:\>perl -MDevel::Modlist script.pl ActivePerl::Config ActiveState::Path 1.01 AutoLoader 5.70 C:::Perl::site::lib::sitecustomize.pl Carp 1.10 Config Config_heavy.pl Cwd 3.31 DynaLoader 1.0901 Exporter 5.63 Exporter::Heavy 5.63 File::Basename 2.77 File::Spec 3.31 File::Spec::Unix 3.3 File::Spec::Win32 3.3 Time::Local 1.1901 Win32 0.39 Win32::API 0.59 Win32::API::Struct 0.50 Win32::API::Type 0.59 Win32::OLE 0.1709 Win32::OLE::Const Win32::OLE::Lite Win32::OLE::Variant Win32::Process::Info 1.016 Win32::Process::Info::WMI 1.016 XSLoader 0.10 base 2.14 constant 1.19 integer 1.00 overload 1.06 re 0.0601 vars 1.01 warnings 1.05_01 warnings::register 1.01

        ...and the following message was also displayed, as per normal for this script:-

        Use of uninitialized value in exists at C:/Perl/site/lib/Win32/Process/Info.pm line 477.
        
        Thanks.