Class: WmiLite::Wmi

Inherits:
Object
  • Object
show all
Defined in:
lib/wmi-lite/wmi.rb,
lib/wmi-lite/wmi_instance.rb

Defined Under Namespace

Classes: Instance

Instance Method Summary collapse

Constructor Details

#initialize(namespace = nil) ⇒ Wmi

Returns a new instance of Wmi.



25
26
27
28
# File 'lib/wmi-lite/wmi.rb', line 25

def initialize(namespace = nil)
  @namespace = namespace.nil? ? "root/cimv2" : namespace
  @connection = nil
end

Instance Method Details

#first_of(wmi_class) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/wmi-lite/wmi.rb', line 38

def first_of(wmi_class)
  query_result = start_query("select * from #{wmi_class}", wmi_class)
  first_result = nil
  query_result.each do |record|
    first_result = record
    break
  end
  first_result.nil? ? nil : wmi_result_to_snapshot(first_result)
end

#instances_of(wmi_class) ⇒ Object



34
35
36
# File 'lib/wmi-lite/wmi.rb', line 34

def instances_of(wmi_class)
  query_with_context("select * from #{wmi_class}", wmi_class)
end

#query(wql_query) ⇒ Object



30
31
32
# File 'lib/wmi-lite/wmi.rb', line 30

def query(wql_query)
  query_with_context(wql_query)
end