I have a little windows application running Ruby 1.9.3 (MRI), and I need it to query the "ComputerName" of a remote registry of a remote server. I have the code for checking the local registry, which looks as follows:
#Gemfile
gem "win32-service", "0.8.2", :platforms => :mingw
# regchecker.rb
require 'win32/registry'
def value_exists?(path,key)
reg_type = Win32::Registry::KEY_READ | 0x100
Win32::Registry::HKEY_LOCAL_MACHINE.open(path, reg_type) do |reg|
begin
regkey = reg[key]
p regkey.inspect
return true
rescue
return false
end
end
end
puts(value_exists?("SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName", 'ComputerName'))
Running this code yields a printout of the local ComputerName registry key as well as a boolean.
However, I cannot find a way to use Ruby and the win32-service gem (or any other gem for that matter) to read the ComputerName from a remote computer for which I have the userid and password. How can I do this using Ruby and win32-service, or some other gem, or even some other command?