Retrieving Windows applications on desktop

Retrieving Windows applications on desktop

am 25.01.2006 05:17:41 von Foo Ji-Haw

Hello all,

This is a longshot, but I'm just gonna put it out and see what I get...

Is there a way in Perl to get a list of all the Windows applications
that are running? Basically applications that show in the Alt-Tab list.
I am just wondering if I can get the desktop coordinates of the
respective windows applications.

Any hint is appreciated.

Thanks.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Retrieving Windows applications on desktop

am 25.01.2006 15:07:22 von Dirk Bremer

> -----Original Message-----
> From: activeperl-bounces@listserv.ActiveState.com
> [mailto:activeperl-bounces@listserv.ActiveState.com] On
> Behalf Of Foo Ji-Haw
> Sent: Tuesday, January 24, 2006 22:18
> To: activeperl@listserv.ActiveState.com
> Subject: Retrieving Windows applications on desktop
>
> Hello all,
>
> This is a longshot, but I'm just gonna put it out and see
> what I get...
>
> Is there a way in Perl to get a list of all the Windows applications
> that are running? Basically applications that show in the
> Alt-Tab list.
> I am just wondering if I can get the desktop coordinates of the
> respective windows applications.
>
> Any hint is appreciated.

Something like this may be a start, although I cannot help you with
obtaining desktop/window coordinates.

use Win32::OLE qw(in);
use Win32::OLE::Variant;
my $WMI = Win32::OLE->GetObject($CLASS) || die('WMI instantiation
failed');
# Find all PIDs, program-names, and executable paths for all running
processes.
for my $Process (sort{lc($a->{Name}) cmp lc($b->{Name})} in
($WMI->InstancesOf("Win32_Process")))
{
$Name = $Process->{Name}; # Process program-name.
$Path = $Process->{ExecutablePath}; # Process executable path.
$PID = $Process->{ProcessID}; # PID.
$Path = '' unless (defined($Path));
}

Dirk Bremer - Senior Systems Engineer - ESS/AMS - NISC Lake St. Louis MO
- USA Central Time Zone
636-755-2652 fax 636-755-2503

dirk.bremer@nisc.coop
www.nisc.coop

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Retrieving Windows applications on desktop

am 26.01.2006 09:14:10 von Foo Ji-Haw

>>Is there a way in Perl to get a list of all the Windows applications
>>that are running? Basically applications that show in the
>>Alt-Tab list.
>>I am just wondering if I can get the desktop coordinates of the
>>respective windows applications.
>>
>>Any hint is appreciated.
>>
>>
>
>Something like this may be a start, although I cannot help you with
>obtaining desktop/window coordinates.
>
>use Win32::OLE qw(in);
>use Win32::OLE::Variant;
>my $WMI = Win32::OLE->GetObject($CLASS) || die('WMI instantiation
>failed');
># Find all PIDs, program-names, and executable paths for all running
>processes.
>for my $Process (sort{lc($a->{Name}) cmp lc($b->{Name})} in
>($WMI->InstancesOf("Win32_Process")))
>{
> $Name = $Process->{Name}; # Process program-name.
> $Path = $Process->{ExecutablePath}; # Process executable path.
> $PID = $Process->{ProcessID}; # PID.
> $Path = '' unless (defined($Path));
>}
>
>
Thanks Dirk,

A working version of your code is as follows:
use strict;
use warnings;

use Win32::OLE qw(in);
use Win32::OLE::Variant;
my $WMI = Win32::OLE->GetObject("winmgmts:\\\\localhost\\root\\cimv2")
|| die('WMI instantiation failed');
for my $Process (sort{lc($a->{Name}) cmp lc($b->{Name})} in
($WMI->InstancesOf("Win32_Process")))
{
my $Name = $Process->{Name}; # Process program-name.
my $Path = $Process->{ExecutablePath}; # Process executable path.
my $PID = $Process->{ProcessID}; # PID.
$Path = '' unless (defined($Path));

print "$Name,$Path,$PID\n";
}

WMI is a good start, but I don't think it exposes the application screen
coordinates.

Thanks anyway.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Retrieving Windows applications on desktop

am 26.01.2006 11:45:21 von rvtol+news

Foo Ji-Haw schreef:

> my $WMI = Win32::OLE->GetObject("winmgmts:\\\\localhost\\root\\cimv2")

Alternatives:

my $WMI = Win32::OLE->GetObject( 'winmgmts:\\localhost\root\cimv2' )

my $WMI = Win32::OLE->GetObject( q{winmgmts:\\localhost\root\cimv2} )


> print "$Name,$Path,$PID\n";

Alternative:

{ local ($,, $\) = (',', "\n"); # or (q{,}, qq{\n})
print $Name, $Path, $PID;
}

--
Affijn, Ruud

"Gewoon is een tijger."


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Retrieving Windows applications on desktop

am 26.01.2006 20:24:05 von Howard Tanner

>>Is there a way in Perl to get a list of all the Windows applications
>>that are running? Basically applications that show in the
>>Alt-Tab list.
>>I am just wondering if I can get the desktop coordinates of the
>>respective windows applications.
>>
>>Any hint is appreciated.
>>
>
> WMI is a good start, but I don't think it exposes the application screen
> coordinates.
>
>

I could not find a way to get this info from WMI either.

However, what I think you're really looking for are the coordinates
for the top level windows, so there's no need for the processes. To do
this, you need to use the following Windows API's:

EnumWindows (uses a callback to identify each top-level window)
GetWindowText (to get the title of the window)
GetWindowInfo (returns a WINDOWINFO struct, which contains RECT
rcWindow, which is what you're looking for)

These API's are documented at Microsoft's MSDN library:
http://msdn.microsoft.com/library. Basically, the EnumWindows callback
is passed a window handle (hwnd) for each top-level window. The hwnd
can then be passed to GetWindowText and GetWindowInfo to get the
information you need about that window.

This is easy enough in a language that can call Windows API's but this
is beyond my current Perl skills. There's a Win32::API module that
might do the trick, but I can't see how to do the callback with it.
Perhaps an XS is the way to go, but that's beyond me right now, and
perhaps way more complicated than simply using a language that can
call Windows API's...

Perhaps someone else on this list can use this info to craft the Perl
you need...

Good luck,
HT

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Retrieving Windows applications on desktop

am 26.01.2006 21:36:50 von JKahn

This is a multipart message in MIME format.
--===============0092567967==
Content-Type: multipart/alternative;
boundary="=_alternative 00713CA985257102_="

This is a multipart message in MIME format.
--=_alternative 00713CA985257102_=
Content-Type: text/plain; charset="US-ASCII"

Here is a way to do it with WMI. Got this by quickly editing a
scriptomatic generated script:


On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_SoftwareFeature where vendor like '%Microsoft%'", "WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)

For Each objItem In colItems
WScript.Echo "Accesses: " & objItem.Accesses
WScript.Echo "Attributes: " & objItem.Attributes
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "Description: " & objItem.Description
WScript.Echo "IdentifyingNumber: " & objItem.IdentifyingNumber
WScript.Echo "InstallDate: " &
WMIDateStringToDate(objItem.InstallDate)
WScript.Echo "InstallState: " & objItem.InstallState
WScript.Echo "LastUse: " & WMIDateStringToDate(objItem.LastUse)
WScript.Echo "Name: " & objItem.Name
WScript.Echo "ProductName: " & objItem.ProductName
WScript.Echo "Status: " & objItem.Status
WScript.Echo "Vendor: " & objItem.Vendor
WScript.Echo "Version: " & objItem.Version
WScript.Echo
Next
Next


Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" &
Mid(dtmDate,13, 2))
End Function



JK




Howard Tanner
Sent by: activeperl-bounces@listserv.ActiveState.com
01/26/2006 02:24 PM

To
Foo Ji-Haw
cc
activeperl@listserv.ActiveState.com
Subject
Re: Retrieving Windows applications on desktop






>>Is there a way in Perl to get a list of all the Windows applications
>>that are running? Basically applications that show in the
>>Alt-Tab list.
>>I am just wondering if I can get the desktop coordinates of the
>>respective windows applications.
>>
>>Any hint is appreciated.
>>
>
> WMI is a good start, but I don't think it exposes the application screen
> coordinates.
>
>

I could not find a way to get this info from WMI either.

However, what I think you're really looking for are the coordinates
for the top level windows, so there's no need for the processes. To do
this, you need to use the following Windows API's:

EnumWindows (uses a callback to identify each top-level window)
GetWindowText (to get the title of the window)
GetWindowInfo (returns a WINDOWINFO struct, which contains RECT
rcWindow, which is what you're looking for)

These API's are documented at Microsoft's MSDN library:
http://msdn.microsoft.com/library. Basically, the EnumWindows callback
is passed a window handle (hwnd) for each top-level window. The hwnd
can then be passed to GetWindowText and GetWindowInfo to get the
information you need about that window.

This is easy enough in a language that can call Windows API's but this
is beyond my current Perl skills. There's a Win32::API module that
might do the trick, but I can't see how to do the callback with it.
Perhaps an XS is the way to go, but that's beyond me right now, and
perhaps way more complicated than simply using a language that can
call Windows API's...

Perhaps someone else on this list can use this info to craft the Perl
you need...

Good luck,
HT

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



************************************************************ *******

This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity
to whom they are addressed. If you have received this
email in error please notify the sender by replying to this
email and then delete it from your system.

No reliance may be placed upon this email without written
confirmation of its contents and any liability arising from
such reliance without written confirmation is hereby
excluded.

JRI America

************************************************************ *******


--=_alternative 00713CA985257102_=
Content-Type: text/html; charset="US-ASCII"



Here is a way to do it with WMI.  Got
this by quickly editing a scriptomatic generated script:






On Error Resume Next



Const wbemFlagReturnImmediately = &h10

Const wbemFlagForwardOnly = &h20



arrComputers = Array("<COMPUTERNAME>")

For Each strComputer In arrComputers

   WScript.Echo

   WScript.Echo "=========================================="

   WScript.Echo "Computer:
" & strComputer


   WScript.Echo "=========================================="



   Set objWMIService = GetObject("winmgmts:\\"
& strComputer & "\root\CIMV2")


   Set colItems = objWMIService.ExecQuery("SELECT
* FROM Win32_SoftwareFeature where vendor like '%Microsoft%'", "WQL",
_


           
                     
        wbemFlagReturnImmediately + wbemFlagForwardOnly)




   For Each objItem In colItems

      WScript.Echo "Accesses:
" & objItem.Accesses


      WScript.Echo "Attributes:
" & objItem.Attributes


      WScript.Echo "Caption:
" & objItem.Caption


      WScript.Echo "Description:
" & objItem.Description


      WScript.Echo "IdentifyingNumber:
" & objItem.IdentifyingNumber


      WScript.Echo "InstallDate:
" & WMIDateStringToDate(objItem.InstallDate)


      WScript.Echo "InstallState:
" & objItem.InstallState


      WScript.Echo "LastUse:
" & WMIDateStringToDate(objItem.LastUse)


      WScript.Echo "Name:
" & objItem.Name


      WScript.Echo "ProductName:
" & objItem.ProductName


      WScript.Echo "Status:
" & objItem.Status


      WScript.Echo "Vendor:
" & objItem.Vendor


      WScript.Echo "Version:
" & objItem.Version


      WScript.Echo

   Next

Next





Function WMIDateStringToDate(dtmDate)

WScript.Echo dtm:

        WMIDateStringToDate
= CDate(Mid(dtmDate, 5, 2) & "/" & _


        Mid(dtmDate,
7, 2) & "/" & Left(dtmDate, 4) _


        &
" " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate,
11, 2) & ":" & Mid(dtmDate,13, 2))


End Function







JK










Howard Tanner <htanner@gmail.com>


Sent by: activeperl-bounces@listserv.ActiveState.com

01/26/2006 02:24 PM







To

Foo Ji-Haw <jhfoo-ml@extracktor.com>

cc

activeperl@listserv.ActiveState.com

Subject

Re: Retrieving Windows applications
on desktop














>>Is there a way in Perl to get a list of all
the Windows applications

>>that are running? Basically applications that show in the

>>Alt-Tab list.

>>I am just wondering if I can get the desktop coordinates of the

>>respective windows applications.

>>

>>Any hint is appreciated.

>>

>

> WMI is a good start, but I don't think it exposes the application
screen

> coordinates.

>

>



I could not find a way to get this info from WMI either.



However, what I think you're really looking for are the coordinates

for the top level windows, so there's no need for the processes. To do

this, you need to use the following Windows API's:



EnumWindows (uses a callback to identify each top-level window)

GetWindowText (to get the title of the window)

GetWindowInfo (returns a WINDOWINFO struct, which contains RECT

rcWindow, which is what you're looking for)



These API's are documented at Microsoft's MSDN library:

http://msdn.microsoft.com/library. Basically, the EnumWindows callback

is passed a window handle (hwnd) for each top-level window. The hwnd

can then be passed to GetWindowText and GetWindowInfo to get the

information you need about that window.



This is easy enough in a language that can call Windows API's but this

is beyond my current Perl skills. There's a Win32::API module that

might do the trick, but I can't see how to do the callback with it.

Perhaps an XS is the way to go, but that's beyond me right now, and

perhaps way more complicated than simply using a language that can

call Windows API's...



Perhaps someone else on this list can use this info to craft the Perl

you need...



Good luck,

HT



_______________________________________________

ActivePerl mailing list

ActivePerl@listserv.ActiveState.com

To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs







************************************************************ *******



This email and any files transmitted with it are confidential

and intended solely for the use of the individual or entity

to whom they are addressed. If you have received this

email in error please notify the sender by replying to this

email and then delete it from your system.



No reliance may be placed upon this email without written

confirmation of its contents and any liability arising from

such reliance without written confirmation is hereby

excluded.



JRI America



************************************************************ *******



--=_alternative 00713CA985257102_=--

--===============0092567967==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0092567967==--

Re: Retrieving Windows applications on desktop

am 27.01.2006 02:55:43 von Foo Ji-Haw

>I could not find a way to get this info from WMI either.
>
>However, what I think you're really looking for are the coordinates
>for the top level windows, so there's no need for the processes. To do
>this, you need to use the following Windows API's:
>
>EnumWindows (uses a callback to identify each top-level window)
>GetWindowText (to get the title of the window)
>GetWindowInfo (returns a WINDOWINFO struct, which contains RECT
>rcWindow, which is what you're looking for)
>
>These API's are documented at Microsoft's MSDN library:
>http://msdn.microsoft.com/library. Basically, the EnumWindows callback
>is passed a window handle (hwnd) for each top-level window. The hwnd
>can then be passed to GetWindowText and GetWindowInfo to get the
>information you need about that window.
>
>
I think your angle is heading in the right direction. I found a module
called Win32::CaptureIE that does a screenshot capture of an IE browser
(cool right?). I may be able to glean some tricks off the codes, but the
main difference is that the module creates its own object (via
GetObject), so it is able to get the hwnd. But with your EnumWindows
suggestion it may just work...


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Retrieving Windows applications on desktop

am 27.01.2006 03:52:05 von Foo Ji-Haw

>> However, what I think you're really looking for are the coordinates
>> for the top level windows, so there's no need for the processes. To do
>> this, you need to use the following Windows API's:
>>
>> EnumWindows (uses a callback to identify each top-level window)
>> GetWindowText (to get the title of the window)
>> GetWindowInfo (returns a WINDOWINFO struct, which contains RECT
>> rcWindow, which is what you're looking for)
>>
>> These API's are documented at Microsoft's MSDN library:
>> http://msdn.microsoft.com/library. Basically, the EnumWindows callback
>> is passed a window handle (hwnd) for each top-level window. The hwnd
>> can then be passed to GetWindowText and GetWindowInfo to get the
>> information you need about that window.
>
Apparently someone has already done it, via another module! Look at
Win32::GuiTest. You can use FindWindowLike() and GetWindowText() to list
all windows, and get their screen locations respectively.

The following is a simple sample code:
use Win32::GuiTest qw(FindWindowLike GetWindowText GetWindowRect);

my @windows = FindWindowLike();
foreach my $window (@windows)
{
my $WindowText = GetWindowText($window);
if ($WindowText and ($WindowText =~ /Thunderbird/))
{
print "$window,".GetWindowText($window)."\n";
my @rect = GetWindowRect($window);
print 'rect: '.join(',',@rect)."\n";
}
}

Cool! Perl rocks!
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs