Created
May 18, 2012 16:31
-
-
Save joshcooper/2726251 to your computer and use it in GitHub Desktop.
Test what the domain fact would change to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'win32ole' | |
require 'win32/registry' | |
def connect(uri = wmi_resource_uri) | |
WIN32OLE.connect(uri) | |
end | |
def wmi_resource_uri( host = '.' ) | |
"winmgmts:{impersonationLevel=impersonate}!//#{host}/root/cimv2" | |
end | |
def execquery(query) | |
connect().execquery(query) | |
end | |
def hklm_read(key, value) | |
Win32::Registry::HKEY_LOCAL_MACHINE.open(key) {|reg| reg[value]} | |
end | |
primary = hklm_read('SYSTEM\CurrentControlSet\Services\Tcpip\Parameters', 'Domain') | |
puts "primary : #{primary}" | |
dnsdomain = "" | |
execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic| | |
dnsdomain = nic.DNSDomain | |
break | |
} | |
puts "interface: #{dnsdomain}" | |
if primary.empty? or primary == dnsdomain | |
puts "domain would not change" | |
else | |
puts "domain would change from '#{dnsdomain}' to '#{primary}'" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment