diff options
Diffstat (limited to 'lib/wmi-lite/wmi.rb')
-rw-r--r-- | lib/wmi-lite/wmi.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/wmi-lite/wmi.rb b/lib/wmi-lite/wmi.rb index b712ba9..6c39479 100644 --- a/lib/wmi-lite/wmi.rb +++ b/lib/wmi-lite/wmi.rb @@ -61,12 +61,12 @@ module WmiLite def start_query(wql_query, diagnostic_class_name = nil) result = nil + connect_to_namespace begin - connect_to_namespace result = @connection.ExecQuery(wql_query) raise_if_failed(result) rescue WIN32OLERuntimeError => native_exception - raise WmiException.new(native_exception, @namespace, wql_query, diagnostic_class_name) + raise WmiException.new(native_exception, :ExecQuery, @namespace, wql_query, diagnostic_class_name) end result end @@ -82,7 +82,11 @@ module WmiLite if @connection.nil? namespace = @namespace.nil? ? 'root/cimv2' : @namespace locator = WIN32OLE.new("WbemScripting.SWbemLocator") - @connection = locator.ConnectServer('.', namespace) + begin + @connection = locator.ConnectServer('.', namespace) + rescue WIN32OLERuntimeError => native_exception + raise WmiException.new(native_exception, :ConnectServer, @namespace) + end end end |