What is it?

ruby-wmi is an ActiveRecord style interface for Microsoft's Windows Management Instrumentation provider.

Many of the methods in WMI::Base are borrowed directly, or with some modification from ActiveRecord.

The major tool in this library is the #find method. For more information, see WMI::Base.

There is also a WMI.sublasses method included for reflection.

How do I install it?

  • gem install ruby-wmi

What does it look like?

  • samples/disk.rb
    require 'ruby-wmi'
    
    disks = WMI::Win32_LogicalDisk.find(:all)
    
    disks.each do |disk|
     disk.properties_.each do |p|
        puts "#{p.name}: #{disk[p.name]}"
      end
    end
    
  • samples/logoff.rb
    require 'ruby-wmi'
    
    LOGOFF = 0
    
    host = 'computername'
    host = WMI::Win32_OperatingSystem.find(:first, :conditions => {:primary => true}, :host => host)
    host.win32shutdown(LOGOFF)
    
    
  • samples/memory.rb
    require 'ruby-wmi'
    
    properties = ['Description','MaxCapacity','MemoryDevices','MemoryErrorCorrection']
    
    
    mem = WMI::Win32_PhysicalMemoryArray.find(:all, :host => 'server1')
    mem.each{|i| puts properties.map{|p| "#{p}: #{i[p]}"}}
    
    mem2 = WMI::Win32_PhysicalMemoryArray.find(:all, {:host => 'server2', :user => 'domain\\gordon', :passwd => 'password'} )
    mem2.each{|i| puts properties.map{|p| "#{p}: #{i[p]}"}}