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

**URL:** https://rubytalk.org/t/autoit-over-ruby-question-how-do-i-call-objget/45833
**Category:** ruby-talk
**Created:** [12 April 2008 12:45 UTC](https://rubytalk.org/t/autoit-over-ruby-question-how-do-i-call-objget/45833 "2008-04-12T12:45:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Sean\_Nakasone](https://avatars.discourse-cdn.com/v4/letter/s/e9a140/32.png) [@Sean\_Nakasone](https://rubytalk.org/u/Sean_Nakasone)
#### Post date: [12 April 2008 12:45 UTC](https://rubytalk.org/t/autoit-over-ruby-question-how-do-i-call-objget/45833/1 "2008-04-12T12:45:04Z")

</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: ![David\_Mullet](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@David\_Mullet](https://rubytalk.org/u/David_Mullet)
#### Post date: [12 April 2008 15:36 UTC](https://rubytalk.org/t/autoit-over-ruby-question-how-do-i-call-objget/45833/2 "2008-04-12T15:36:34Z")

</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  
&nbsp;&nbsp;begin  
&nbsp;&nbsp;&nbsp;&nbsp;if window.Document.Title =~ /Yahoo/  
&nbsp;&nbsp;&nbsp;&nbsp;ie = window  
&nbsp;&nbsp;end  
&nbsp;&nbsp;rescue  
&nbsp;&nbsp;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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![W\_James](https://avatars.discourse-cdn.com/v4/letter/w/e274bd/32.png) [@W\_James](https://rubytalk.org/u/W_James)
#### Post date: [13 April 2008 08:45 UTC](https://rubytalk.org/t/autoit-over-ruby-question-how-do-i-call-objget/45833/3 "2008-04-13T08:45:06Z")

</div>

This seems not to work.

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

--- output ---  
"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"  
"Microsoft Internet Explorer"  
""  
nil

> **···**
>
> On Apr 12, 10:36 am, David Mullet \<david.mul...@gmail.com\> wrote:
> 
> > 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  
> > &nbsp;&nbsp;begin  
> > &nbsp;&nbsp;&nbsp;&nbsp;if window.Document.Title =~ /Yahoo/  
> > &nbsp;&nbsp;&nbsp;&nbsp;ie = window  
> > &nbsp;&nbsp;end  
> > &nbsp;&nbsp;rescue  
> > &nbsp;&nbsp;end  
> > end

---

<div class="post-metadata">

### Author: ![David\_Mullet](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@David\_Mullet](https://rubytalk.org/u/David_Mullet)
#### Post date: [13 April 2008 12:20 UTC](https://rubytalk.org/t/autoit-over-ruby-question-how-do-i-call-objget/45833/4 "2008-04-13T12:20:44Z")

</div>

William James wrote:

> This seems not to work.
> 
> require 'win32ole'  
> ie = nil  
> WIN32OLE.new('Shell.Application').Windows.each do |window|  
> &nbsp;&nbsp;p window.FullName  
> &nbsp;&nbsp;p window.Name  
> &nbsp;&nbsp;begin  
> &nbsp;&nbsp;&nbsp;&nbsp;title = window.Document.Title  
> &nbsp;&nbsp;&nbsp;&nbsp;p title  
> &nbsp;&nbsp;&nbsp;&nbsp;if title =~ /Internet Explorer/  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ie = window  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;rescue  
> &nbsp;&nbsp;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...

&nbsp;&nbsp;if window.Document.Title =~ /Internet Explorer/

will usually NOT work, though...

&nbsp;&nbsp;if window.Name =~ /Internet Explorer/

...would work.

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

You could test the Type property:

&nbsp;&nbsp;if window.Type == 'HTML Document'

or you could test the window.Name property:

&nbsp;&nbsp;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

&nbsp;&nbsp;if window.Document.Title =~ /Yahoo/

&nbsp;&nbsp;if window.LocationName =~ /Yahoo/

David

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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![David\_Mullet](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@David\_Mullet](https://rubytalk.org/u/David_Mullet)
#### Post date: [13 April 2008 23:00 UTC](https://rubytalk.org/t/autoit-over-ruby-question-how-do-i-call-objget/45833/5 "2008-04-13T23:00:34Z")

</div>

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

&nbsp;&nbsp;if window.Document.Title =~ /Internet Explorer/

will usually NOT work, though...

&nbsp;&nbsp;if window.Name =~ /Internet Explorer/

...would work.

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

You could test the Type property:

&nbsp;&nbsp;if window.Type == 'HTML Document'

or you could test the window.Name property:

&nbsp;&nbsp;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

&nbsp;&nbsp;if window.Document.Title =~ /Yahoo/

&nbsp;&nbsp;if window.LocationName =~ /Yahoo/

David

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

> **···**
>
> On Apr 13, 8:20 am, David Mullet \<david.mul...@gmail.com\> wrote:
> 
> > William James 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

---

<div class="post-metadata">

### Author: ![W\_James](https://avatars.discourse-cdn.com/v4/letter/w/e274bd/32.png) [@W\_James](https://rubytalk.org/u/W_James)
#### Post date: [13 April 2008 23:50 UTC](https://rubytalk.org/t/autoit-over-ruby-question-how-do-i-call-objget/45833/6 "2008-04-13T23:50:03Z")

</div>

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

> **···**
>
> On Apr 13, 5:56 pm, mully \<david.mul...@gmail.com\> wrote:
> 
> > On Apr 13, 8:20 am, David Mullet \<david.mul...@gmail.com\> wrote:
> > 
> > \> William James 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
> > 
> > [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...
