如何在 Windows 中使用 Ruby 获取已安装应用程序的列表?

发布于 2024-09-30 05:21:12 字数 669 浏览 3 评论 0原文

我知道使用 wmi 查询 WIN32_product 可以读取已安装应用程序的列表,但该列表与控制面板下的添加/删除程序列表不同。 另一种方法是读取 Windows 注册表中的 Software\Microsoft\Windows\CurrentVersion\Uninstall ?

我正在使用以下几行 ruby​​ 代码来执行此操作,但它不起作用

对于此示例,我正在寻找名为 Branding 的软件(当我在 Windows 7 PC 中进行 regedit 时它会显示)

Win32::Registry::HKEY_LOCAL_MACHINE.open('Software\Microsoft\Windows\CurrentVersion\Uninstall\Branding') do |reg|
  reg_typ, reg_val = reg.read('')
  return reg_val
end

运行后出现错误消息这段代码

win32/registry.rb:528:in `open': The system cannot find
the file specified. (Win32::Registry::Error)
        from win32/registry.rb:608:in `open'

这段代码有什么问题?

I know that using wmi query WIN32_product one can read the list of installed applications but the list is different from add/remove program list under control panel.
Another approach would be to read Software\Microsoft\Windows\CurrentVersion\Uninstall in windows registry?

I am using the following few lines of ruby code to do that but it is not working

For this example I am looking for a software by the name of Branding (it shows when I go thru regedit in my windows 7 PC)

Win32::Registry::HKEY_LOCAL_MACHINE.open('Software\Microsoft\Windows\CurrentVersion\Uninstall\Branding') do |reg|
  reg_typ, reg_val = reg.read('')
  return reg_val
end

Error Message after running this piece of code

win32/registry.rb:528:in `open': The system cannot find
the file specified. (Win32::Registry::Error)
        from win32/registry.rb:608:in `open'

What is wrong with this piece of code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

用心笑 2024-10-07 05:21:12
Win32::Registry::HKEY_LOCAL_MACHINE.open(
  'Software\Microsoft\Windows\CurrentVersion\Uninstall'
) do |reg|
  reg.each_key do |key|
    k = reg.open(key)

    puts key
    puts k["DisplayName"]    rescue "?"
    puts k["DisplayVersion"] rescue "?"
    puts k["Publisher"]      rescue "?"
    puts k["URLInfoAbout"]   rescue "?"
    puts
  end
end

但要注意:“Software\Wow6432Node\Windows\CurrentVersion\Uninstall”

Win32::Registry::HKEY_LOCAL_MACHINE.open(
  'Software\Microsoft\Windows\CurrentVersion\Uninstall'
) do |reg|
  reg.each_key do |key|
    k = reg.open(key)

    puts key
    puts k["DisplayName"]    rescue "?"
    puts k["DisplayVersion"] rescue "?"
    puts k["Publisher"]      rescue "?"
    puts k["URLInfoAbout"]   rescue "?"
    puts
  end
end

Though beware of: 'Software\Wow6432Node\Windows\CurrentVersion\Uninstall'

掩耳倾听 2024-10-07 05:21:12
key = 'Software\Microsoft\Windows\CurrentVersion\Uninstall'
reg_type = Win32::Registry::Constants::KEY_READ | Windows::Registry::KEY_WOW64_64KEY

Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE,key,reg_type) do |reg|
 reg.each_key do |key|
     k = reg.open(key)

     puts key
     puts k["DisplayName"]    rescue "?"
     puts k["DisplayVersion"] rescue "?"
     puts k["Publisher"]      rescue "?"
     puts k["URLInfoAbout"]   rescue "?"
     puts
   end
 end

查看此链接,了解如何操作的说明注册表适用于 64 位平台

key = 'Software\Microsoft\Windows\CurrentVersion\Uninstall'
reg_type = Win32::Registry::Constants::KEY_READ | Windows::Registry::KEY_WOW64_64KEY

Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE,key,reg_type) do |reg|
 reg.each_key do |key|
     k = reg.open(key)

     puts key
     puts k["DisplayName"]    rescue "?"
     puts k["DisplayVersion"] rescue "?"
     puts k["Publisher"]      rescue "?"
     puts k["URLInfoAbout"]   rescue "?"
     puts
   end
 end

Check out this link for an explanation of how the registry works on 64 bit platforms

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文