Module: RubyWMI

Extended by:
RubyWMI
Included in:
RubyWMI
Defined in:
lib/ruby-wmi.rb,
lib/ruby-wmi/base.rb,
lib/ruby-wmi/errors.rb,
lib/ruby-wmi/version.rb,
lib/ruby-wmi/privilege.rb

Defined Under Namespace

Modules: Privilege Classes: Base, InvalidClass, InvalidNameSpace, InvalidQuery, ReadOnlyError, WMIError

Constant Summary collapse

VERSION =
'0.4.0'

Instance Method Summary collapse

Instance Method Details

#const_missing(name) ⇒ Object



81
82
83
# File 'lib/ruby-wmi.rb', line 81

def const_missing(name)
  self.const_set(name, Class.new(self::Base))
end

#instances_of(options) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/ruby-wmi.rb', line 71

def instances_of(options)
  Base.set_connection(options)
  conn = Base.send(:connection)
  items = namespaces = conn.send(options[:method], options[:instance])
  Base.send(:clear_connection_options)
  items
end

#namespaces(options = {}) ⇒ Object Also known as: namespaces_of

Returns an array containing all the WMI namespaces on a sytem. Defaults to localhost

 WMI.namespaces

For a more human readable version of namespaces when using options:

 WMI.namespaces_of(:host => :some_computer)

 WMI.namespaces_of(:namespace => "root\\Microsoft")


59
60
61
62
63
64
65
66
67
68
# File 'lib/ruby-wmi.rb', line 59

def namespaces(options ={})
  options.merge!(:method => :InstancesOf, :instance => "__NAMESPACE")
  options[:namespace] ||= 'root'
  instances_of(options).
  map{ |namespace|
    namespace = "#{options[:namespace]}\\#{namespace.name}"
    ns = namespaces(options.merge(:namespace => namespace)) rescue nil
    [namespace, ns]
  }.flatten
end

#providers(options = {}) ⇒ Object Also known as: providers_of

Returns an array containing all the WMI providers on a sytem. Defaults to localhost

 WMI.providers

For a more human readable version of providers when using options:

 WMI.providers_of(:host => :some_computer)


42
43
44
45
46
# File 'lib/ruby-wmi.rb', line 42

def providers(options ={})
  options.merge!(:method => :InstancesOf, :instance => "__Win32Provider")
  instances_of(options).
  map{ |provider| provider.name }.compact
end

#subclasses(options = {}) ⇒ Object Also known as: subclasses_of

Returns an array containing all the WMI subclasses on a sytem. Defaults to localhost

 WMI.subclasses
 => ["Win32_PrivilegesStatus", "Win32_TSNetworkAdapterSettingError", ...]

For a more human readable version of subclasses when using options:

 WMI.subclasses_of(:host => 'some_computer')
 => ["Win32_PrivilegesStatus", "Win32_TSNetworkAdapterSettingError", ...]

 WMI.subclasses_of(
    :host => :some_computer,
    :namespace => "root\\Microsoft\\SqlServer\\ComputerManagement"
  )


27
28
29
30
31
# File 'lib/ruby-wmi.rb', line 27

def subclasses(options ={})
  options.merge!(:method => :SubclassesOf)
  instances_of(options).
  map{ |subclass| subclass.Path_.Class }
end