# AutoIt over Ruby question - How do I call ObjGet()?

**URL:** <https://www.ruby-forum.com/t/autoit-over-ruby-question-how-do-i-call-objget/134592>\
**Category:** Ruby\
**Created:** [April 12, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/autoit-over-ruby-question-how-do-i-call-objget/134592 "2008-04-12T14:45:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [April 12, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/autoit-over-ruby-question-how-do-i-call-objget/134592/1 "2008-04-12T14:45:52Z")

</div>

Here’s an example of using autoit inside of ruby.

require ‘win32ole’  
autoit = WIN32OLE.new(“AutoItX3.Control”)  
autoit.WinActivate(‘Yahoo!’)

So if this works, how come this doesn’t work?

require ‘win32ole’  
autoit = WIN32OLE.new(“AutoItX3.Control”)  
obj=autoit.ObjGet(’’,‘InternetExplorer.Application’)

How do I call the ObjGet() function? In other words, what COM object  
contains that method?

---

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [April 12, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/autoit-over-ruby-question-how-do-i-call-objget/134592/2 "2008-04-12T17:36:31Z")

</div>

sean\_n wrote:

> Here’s an example of using autoit inside of ruby.
> 
> require ‘win32ole’  
> autoit = WIN32OLE.new(“AutoItX3.Control”)  
> autoit.WinActivate(‘Yahoo!’)
> 
> So if this works, how come this doesn’t work?
> 
> require ‘win32ole’  
> autoit = WIN32OLE.new(“AutoItX3.Control”)  
> obj=autoit.ObjGet(‘’,‘InternetExplorer.Application’)
> 
> How do I call the ObjGet() function? In other words, what COM object  
> contains that method?

I can’t offer much help with regard to AutoIt, but you can connect to an  
existing instance of IE using win32ole and the Shell object’s Windows  
collection:

ie = nil  
for window in WIN32OLE.new(‘Shell.Application’).Windows  
begin  
if window.Document.Title =~ /Yahoo/  
ie = window  
end  
rescue  
end  
end

Further details here:

> **[The Shell Windows Collection of Internet Explorer Objects](http://rubyonwindows.blogspot.com/2007/05/shell-windows-collection-of-internet.html)**
>
> As mentioned previously , you cannot use the WIN32OLE.connect method to connect to a running instance of Internet Explorer, as you would do...

Hope that helps!

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [April 13, 2008, 10:45am UTC](https://www.ruby-forum.com/t/autoit-over-ruby-question-how-do-i-call-objget/134592/3 "2008-04-13T10:45:43Z")

</div>

On Apr 12, 10:36 am, David M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > autoit = WIN32OLE.new(“AutoItX3.Control”)  
> > for window in WIN32OLE.new(‘Shell.Application’).Windows  
> > begin  
> > if window.Document.Title =~ /Yahoo/  
> > ie = window  
> > end  
> > rescue  
> > end  
> > end

This seems not to work.

require ‘win32ole’  
ie = nil  
WIN32OLE.new(‘Shell.Application’).Windows.each do |window|  
p window.FullName  
p window.Name  
begin  
title = window.Document.Title  
p title  
if title =~ /Internet Explorer/  
ie = window  
end  
rescue  
end  
end  
p ie

— output —  
“C:\Program Files\Internet Explorer\IEXPLORE.EXE”  
“Microsoft Internet Explorer”  
“”  
nil

---

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [April 14, 2008, 1:04am UTC](https://www.ruby-forum.com/t/autoit-over-ruby-question-how-do-i-call-objget/134592/4 "2008-04-14T01:04:12Z")

</div>

On Apr 13, 8:20 am, David M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > p title
> > 
> > ```
> > 
> > “Microsoft Internet Explorer”  
> > “”  
> > nil
> 
> A key distinction here is between window.Name and window.Document.Title

[Re-posting my reply, as it seems to have been truncated on Google  
Groups…]

A key distinction here is between window.Name and  
window.Document.Title.

window.Document.Title is the Title as defined in the HTML code of a  
window with a Type of “HTML Document”. This probably equates to the  
window.LocationName property. The titlebar text will include both  
window.Document.Title and window.Name, so…

if window.Document.Title =~ /Internet Explorer/

will usually NOT work, though…

if window.Name =~ /Internet Explorer/

…would work.

To grab an IE window from the Shell.Application.Windows collection…

You could test the Type property:

if window.Type == ‘HTML Document’

or you could test the window.Name property:

if window.Name =~ /Internet Explorer/

But to grab a _particular_ IE window from the  
Shell.Application.Windows  
collection, you could use the window.Document.Title or  
window.LocationName property

if window.Document.Title =~ /Yahoo/

if window.LocationName =~ /Yahoo/

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [April 14, 2008, 1:50am UTC](https://www.ruby-forum.com/t/autoit-over-ruby-question-how-do-i-call-objget/134592/5 "2008-04-14T01:50:25Z")

</div>

On Apr 13, 5:56 pm, mully [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > p window.FullName  
> > > p ie  
> > > Groups…]
> 
> A key distinction here is between window.Name and  
> window.Document.Title.
> 
> window.Document.Title is the Title as defined in the HTML code of a  
> window with a Type of “HTML Document”. This probably equates to the  
> window.LocationName property. The titlebar text will include both  
> window.Document.Title and window.Name, so…

The problem was that I had no html document loaded; the titlebar  
text was “about:blank - Microsoft Internet Explorer” but  
window.Document.Title was simply “”.

---

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [April 13, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/autoit-over-ruby-question-how-do-i-call-objget/134592/6 "2008-04-13T14:20:42Z")

</div>

William J. wrote:

> This seems not to work.
> 
> require ‘win32ole’  
> ie = nil  
> WIN32OLE.new(‘Shell.Application’).Windows.each do |window|  
> p window.FullName  
> p window.Name  
> begin  
> title = window.Document.Title  
> p title  
> if title =~ /Internet Explorer/  
> ie = window  
> end  
> rescue  
> end  
> end  
> p ie
> 
> — output —  
> “C:\Program Files\Internet Explorer\IEXPLORE.EXE”  
> “Microsoft Internet Explorer”  
> “”  
> nil

A key distinction here is between window.Name and window.Document.Title  
.

window.Document.Title is the Title as defined in the HTML code of a  
window with a Type of “HTML Document”. This probably equates to the  
window.LocationName property. The titlebar text will include both  
window.Document.Title and window.Name, so…

if window.Document.Title =~ /Internet Explorer/

will usually NOT work, though…

if window.Name =~ /Internet Explorer/

…would work.

To grab an IE window from the Shell.Application.Windows collection…

You could test the Type property:

if window.Type == ‘HTML Document’

or you could test the window.Name property:

if window.Name =~ /Internet Explorer/

But to grab a _particular_ IE window from the Shell.Application.Windows  
collection, you could use the window.Document.Title or  
window.LocationName property

if window.Document.Title =~ /Yahoo/

if window.LocationName =~ /Yahoo/

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform
