mowens has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm beginning to get the hang of working with OLE and Perl. I can't figure out how to scan through all open Internet Explorer windows and identify the one I'm trying to use. I could check the URL if I could only get an OLE path to each window!

This code just seems to take whichever window was opened first:

$IE = Win32::OLE->GetActiveObject('InternetExplorer.Application');

Also, can anyone point me to some good instructions on Perl and Win32::OLE? I've used the Win32::OLE documentation and the Microsoft site.

Thanks,
Mike

Replies are listed 'Best First'.
Re: Scan open InternetExplorer windows with Win32::OLE
by tachyon (Chancellor) on Nov 10, 2004 at 01:43 UTC

    IE is quite a complex beastie under the hood. Anyway you may find this tutorial on Win32::GUITest of use as you can certainly find all the window handles easy enough. Win32::IE::Mechanize may be of use as may the SAMIE project.

    cheers

    tachyon

Re: Scan open InternetExplorer windows with Win32::OLE
by PodMaster (Abbot) on Nov 09, 2004 at 19:45 UTC
    This code just seems to take whichever window was opened first
    What would you expect GetActiveObject to do? I think you should try EnumAllObjects.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Thanks for the reply. On your suggestion I tried EnumAllObjects. As far as I can tell, this method seems to only enum objects created by Win32::OLE or latched onto by GetActiveObject. Running the documentation's example code supports this.
      use Win32::OLE; my $IE = Win32::OLE->GetActiveObject('InternetExplorer.Application'); print $Count = Win32::OLE->EnumAllObjects(sub { my $Object = shift; my $Class = Win32::OLE->QueryObjectType($Object); printf "# Object=%s Class=%s\n", $Object, $Class; });
Re: Scan open InternetExplorer windows with Win32::OLE
by bdimych (Monk) on Nov 27, 2007 at 09:56 UTC
    Following code works for me on winxp, but only a half. I can get access to the "document" dhtml object, but I can not access to the "window". Common way $win->{Document}->{parentWindow} not works, it is always undef for me. (may be because of some msie security restrictions?)
    use strict; use Win32::OLE; my $sh = Win32::OLE->new('Shell.Application'); print "Count is $sh->{Windows}->{Count}\n"; for (my $i = 0; $i < $sh->{Windows}->{Count}; $i++) { my $win = $sh->{Windows}->Item($i); print "Window's #$i document url is '$win->{Document}->{url}'\n"; }
    I think, this is sooner ms then perl issue.