summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam Edwards <adamed@opscode.com>2014-05-15 14:14:01 -0700
committerAdam Edwards <adamed@opscode.com>2014-05-15 14:14:01 -0700
commit1cf40fe00e65ac2e6911bce64154e5111687b90d (patch)
tree65b6391650c78d49a35b7bacd5bc5552fb971586 /lib
parentd9de698a09a1ee4395bd06225e110e966d150e51 (diff)
downloadwmi-lite-1cf40fe00e65ac2e6911bce64154e5111687b90d.tar.gz
Delay connection to first query, not constructor
Diffstat (limited to 'lib')
-rw-r--r--lib/wmi-lite/wmi.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/wmi-lite/wmi.rb b/lib/wmi-lite/wmi.rb
index 1acc9bd..cc6492d 100644
--- a/lib/wmi-lite/wmi.rb
+++ b/lib/wmi-lite/wmi.rb
@@ -22,7 +22,8 @@ require 'wmi-lite/wmi_instance'
module WmiLite
class Wmi
def initialize(namespace = nil)
- @connection = new_connection(namespace.nil? ? 'root/cimv2' : namespace)
+ @namespace = namespace
+ @connection = nil
end
def query(wql_query)
@@ -54,6 +55,7 @@ module WmiLite
private
def start_query(wql_query)
+ connect_to_namespace
result = @connection.ExecQuery(wql_query)
raise_if_failed(result)
result
@@ -66,9 +68,12 @@ module WmiLite
result.count
end
- def new_connection(namespace)
- locator = WIN32OLE.new("WbemScripting.SWbemLocator")
- locator.ConnectServer('.', namespace)
+ def connect_to_namespace
+ if @connection.nil?
+ namespace = @namespace.nil? ? 'root/cimv2' : @namespace
+ locator = WIN32OLE.new("WbemScripting.SWbemLocator")
+ @connection = locator.ConnectServer('.', namespace)
+ end
end
def wmi_result_to_snapshot(wmi_object)