Win32ole WMI fetch

Discussion in 'Ruby' started by morbusg, Aug 8, 2007.

  1. morbusg

    morbusg Guest

    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
     
    morbusg, Aug 8, 2007
    #1
    1. Advertising

  2. >
    > 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] }
     
    Gordon Thiesfeld, Aug 8, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yonatan
    Replies:
    0
    Views:
    135
    yonatan
    Jan 6, 2004
  2. Daniel Berger

    Segfault with win32ole, WMI and structs

    Daniel Berger, May 23, 2004, in forum: Ruby
    Replies:
    4
    Views:
    173
    Jos Backus
    May 24, 2004
  3. Daniel Berger

    Using Win32OLE, WMI and ExecMethod

    Daniel Berger, Jun 3, 2004, in forum: Ruby
    Replies:
    1
    Views:
    204
    Daniel Berger
    Jun 4, 2004
  4. Spike

    WMI and WIN32OLE issues

    Spike, Oct 26, 2006, in forum: Ruby
    Replies:
    0
    Views:
    98
    Spike
    Oct 26, 2006
  5. Nicholas Calvert

    Ruby & WMI (win32ole)

    Nicholas Calvert, Jun 17, 2008, in forum: Ruby
    Replies:
    1
    Views:
    483
    Masaki Suketa
    Jun 18, 2008
Loading...

Share This Page