Skip to content

Instantly share code, notes, and snippets.

@joshcooper
Created May 18, 2012 16:31
Show Gist options
  • Save joshcooper/2726251 to your computer and use it in GitHub Desktop.
Save joshcooper/2726251 to your computer and use it in GitHub Desktop.
Test what the domain fact would change to
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