Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Win32ole WMI fetch

Reply
Thread Tools

Win32ole WMI fetch

 
 
morbusg
Guest
Posts: n/a
 
      08-08-2007
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=imp ersonate}!//
#{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

 
Reply With Quote
 
 
 
 
Gordon Thiesfeld
Guest
Posts: n/a
 
      08-08-2007
>
> require 'win32ole'
> def fetch(where, what)
> wmi = WIN32OLE.connect("winmgmts:{impersonationLevel=imp ersonate}!//
> #{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] }






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruby & WMI (win32ole) Nicholas Calvert Ruby 1 06-18-2008 10:49 AM
WMI and WIN32OLE issues Spike Ruby 0 10-26-2006 06:07 PM
Using Win32OLE, WMI and ExecMethod Daniel Berger Ruby 1 06-04-2004 05:18 AM
Segfault with win32ole, WMI and structs Daniel Berger Ruby 4 05-24-2004 12:53 AM
Ruby.exe crashing with WIN32OLE WMI example? yonatan Ruby 0 01-06-2004 07:10 AM



Advertisments