加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby注册表检查

发布时间:2020-12-16 19:08:38 所属栏目:百科 来源:网络整理
导读:我有以下代码片段,我试图用来验证注册表项(操作系统是 Windows 2008R2或Win7) def value_exists?(path,key) reg_type = Win32::Registry::KEY_READ Win32::Registry::HKEY_LOCAL_MACHINE.open(path,reg_type) do |reg| begin regkey = reg[key] return true
我有以下代码片段,我试图用来验证注册表项(操作系统是 Windows 2008R2或Win7)
def value_exists?(path,key)
  reg_type = Win32::Registry::KEY_READ 
  Win32::Registry::HKEY_LOCAL_MACHINE.open(path,reg_type) do |reg|
    begin
      regkey = reg[key]
      return true
    rescue
      return false
    end
  end
end

当我执行以下2个命令时,预期输出(在我的情况下返回false):

puts(value_exists?("SYSTEMCurrentControlSetControlSession Manager",'PendingFileRenameOperations'))
puts(value_exists?("SOFTWAREMicrosoftWindowsCurrentVersionComponent Based Servicing",'RebootPending'))

当我表演时

puts(value_exists?("SOFTWAREMicrosoftWindowsCurrentVersionWindowsUpdateAuto Update",'RebootRequired'))

我收到以下错误

C:/Ruby187/lib/ruby/1.8/win32/registry.rb:528:in `open': The system cannot find the file specified. (Win32::Registry::Error)
        from C:/Ruby187/lib/ruby/1.8/win32/registry.rb:608:in `open'
        from ./reg2.rb:7:in `value_exists?'
        from ./reg2.rb:21

我真的不明白该怎么做才能做到这一点.我怀疑它可能与x64系统有关,而且无法在正确的位置找到密钥.但我不确定我需要做些什么来解决这个问题.

感谢您的帮助!

解决方法

我想通了 – http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx

reg_type = Win32 :: Registry :: KEY_READ |为0x100

这解决了这个问题!我的猜测是你们没有在x64上测试?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读