# Win32ole WMI fetch

**URL:** <https://www.ruby-forum.com/t/win32ole-wmi-fetch/111595>\
**Category:** Ruby\
**Created:** [August 8, 2007, 10:41pm UTC](https://www.ruby-forum.com/t/win32ole-wmi-fetch/111595 "2007-08-08T22:41:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![morbusg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8dc957/32.png) [@morbusg](https://www.ruby-forum.com/u/morbusg)\
**Post date:** [August 8, 2007, 10:41pm UTC](https://www.ruby-forum.com/t/win32ole-wmi-fetch/111595/1 "2007-08-08T22:41:21Z")

</div>

I wonder what am I missing when trying to put together a script to  
save me some typing.

require ‘win32ole’  
def fetch(where, what)  
wmi = WIN32OLE.connect(“winmgmts:{impersonationLevel=impersonate}!//  
#{ARGV}”)  
qry = wmi.execquery(“select \* from win32\_#{where}”)  
qry.each { |i| print “#{i}.#{what}” }  
end

fetch(“computersystemproduct”, “name”)

The above yields: #WIN32OLE:0x2b369cc.name

If it isn’t obvious, I’m trying to get the ComputerSystemProduct.Name  
printed out via a helper method. I was expecting the model name of the  
computer I’m running.  
TIA

---

<div class="post-metadata">

**Author:** ![morbusg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8dc957/32.png) [@morbusg](https://www.ruby-forum.com/u/morbusg)\
**Post date:** [August 8, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/win32ole-wmi-fetch/111595/2 "2007-08-08T23:10:26Z")

</div>

> require ‘win32ole’  
> def fetch(where, what)  
> wmi = WIN32OLE.connect(“winmgmts:{impersonationLevel=impersonate}!//  
> #{ARGV}”)  
> qry = wmi.execquery(“select \* from win32\_#{where}”)  
> qry.each { |i| print “#{i}.#{what}” }  
> end

You’re using string interpolation, but that’s not what’s needed in  
this case. You actually need to call an ole method on an ole object.

Try this:  
qry.each { |i| print i.send(what) }

Or this:  
qry.each { |i| print i[what] }
