Win32ole WMI fetch

M

morbusg

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
 
G

Gordon Thiesfeld

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] }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top