summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ohai/plugins/root_group.rb38
1 files changed, 12 insertions, 26 deletions
diff --git a/lib/ohai/plugins/root_group.rb b/lib/ohai/plugins/root_group.rb
index 8b290987..3059fcae 100644
--- a/lib/ohai/plugins/root_group.rb
+++ b/lib/ohai/plugins/root_group.rb
@@ -18,33 +18,19 @@
Ohai.plugin(:RootGroup) do
provides "root_group"
- #
- # Performs a WMI query using WIN32OLE from the Ruby Stdlib
- #
- # @return [String]
- #
- def wmi_property_from_query(wmi_property, wmi_query)
- @wmi = ::WIN32OLE.connect("winmgmts://")
- result = @wmi.ExecQuery(wmi_query)
- return nil unless result.each.count > 0
- result.each.next.send(wmi_property)
- end
-
- # Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
- # internal name for the Administrators group, which lets us work
- # properly in environments with a renamed or localized name for the
- # Administrators group.
- # Use LocalAccount=True because otherwise WMI will attempt to include
- # (unneeded) Active Directory groups by querying AD, which is a performance
- # and reliability issue since AD might not be reachable.
- def windows_root_group_name
- wmi_property_from_query(
- :name,
- "select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True"
- )
- end
-
collect_data(:windows) do
+ require "wmi-lite/wmi"
+
+ wmi = WmiLite::Wmi.new
+ # Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
+ # internal name for the Administrators group, which lets us work
+ # properly in environments with a renamed or localized name for the
+ # Administrators group.
+ # Use LocalAccount=True because otherwise WMI will attempt to include
+ # (unneeded) Active Directory groups by querying AD, which is a performance
+ # and reliability issue since AD might not be reachable.
+ groups = wmi.query("select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True")
+ windows_root_group_name = groups[0]["name"]
root_group windows_root_group_name
end