Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Ruby从远程注册表读取值_Ruby_Windows_Winapi_Remote Registry - Fatal编程技术网

如何使用Ruby从远程注册表读取值

如何使用Ruby从远程注册表读取值,ruby,windows,winapi,remote-registry,Ruby,Windows,Winapi,Remote Registry,我有一个运行Ruby 1.9.3(MRI)的小windows应用程序,我需要它来查询远程服务器的远程注册表的“ComputerName”。我有检查本地注册表的代码,如下所示: #Gemfile gem "win32-service", "0.8.2", :platforms => :mingw # regchecker.rb require 'win32/registry' def value_exists?(path,key) reg_type = Win32::Registry

我有一个运行Ruby 1.9.3(MRI)的小windows应用程序,我需要它来查询远程服务器的远程注册表的“ComputerName”。我有检查本地注册表的代码,如下所示:

#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'))
运行此代码将生成本地ComputerName注册表项的打印输出以及布尔值


但是,我找不到一种方法来使用Ruby和win32服务gem(或任何其他gem)从远程计算机读取ComputerName,我有用户ID和密码。我如何使用Ruby和win32服务,或其他一些gem,甚至其他一些命令来做到这一点?

我想这会对您有所帮助。遵循规则。尝试在Ruby中进行转换。在此之前-创建一个像
require'win32ole'这样的对象;obj_swbem_locator=WIN32OLE.new(“WbemScripting.SWbemLocator”)
如果可以,请将代码发布在此处作为答案。我将离开我的办公桌,否则我可以帮你。我遵循了win32ole的链接,但它没有告诉我连接远程服务器或读取注册表的神奇咒语。现在你明白了。。对吧?我想重点是我需要跟上Windows编程的速度。我现在也意识到,这个网站有一些有用的信息。