使用 ruby​​ 查询 Windows 上已安装的软件

发布于 2024-10-25 14:35:25 字数 759 浏览 4 评论 0原文

我想查询Windows机器上所有已安装的软件。我发现另一篇文章正在做类似的事情 here

我稍微修改了代码:

require 'win32/registry'

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

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

这为我提供了一些信息,但我想获得有关该软件的其他信息。例如,最好有安装日期、许可证信息等。

我对 ruby​​ 很陌生。我如何知道 k 的索引或键是什么?显然,“DisplayName”就是其中之一,但我如何找到其他的呢?有没有更好的方法以编程方式获取这些信息?

I want to query all of the installed software on a windows machine. I found another post that was doing something similar here.

I modified the code slightly:

require 'win32/registry'

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

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

This gets me some information, but I'd like to obtain other information about the software. For example, it'd be great to have an installation date, license information, etc.

I'm very new to ruby. How do I know what the indices or keys into k are? Obviously, "DisplayName" is one, but how do I find others? Is there a better way to go about getting this information programmatically?

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

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

发布评论

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

评论(1

小鸟爱天空丶 2024-11-01 14:35:25

如果你只是想了解该软件的完整信息,你可以使用这个:

require 'win32/registry'
require 'pp' # for pretty print

Win32::Registry::HKEY_LOCAL_MACHINE.open('Software\Microsoft\Windows\CurrentVersion\Uninstall') do |reg|
    reg.each_key do |key1,key2|
        k = reg.open(key1)
        pp k.inject([]) {|info, data| info << data}
    end
end

你会得到类似这样的信息:

 ["UninstallString",
  1,
  "\"C:\\WINDOWS\\$NtUninstallKB2393802$\\spuninst\\spuninst.exe\""],
 ["TSAware", 4, 1],
 ["NoModify", 4, 1],
 ["InstallDate", 1, "20110313"],
 ["Publisher", 1, "Microsoft Corporation"],
 ["NoRepair", 4, 1],
 ["HelpLink", 1, "http://support.microsoft.com?kbid=2393802"],
 ["URLInfoAbout", 1, "http://support.microsoft.com"],
 ["DisplayVersion", 1, "1"],
 ["ParentKeyName", 1, "OperatingSystem"],
 ["ParentDisplayName",

等等。

If you just want to know complete information about the software, you can use this:

require 'win32/registry'
require 'pp' # for pretty print

Win32::Registry::HKEY_LOCAL_MACHINE.open('Software\Microsoft\Windows\CurrentVersion\Uninstall') do |reg|
    reg.each_key do |key1,key2|
        k = reg.open(key1)
        pp k.inject([]) {|info, data| info << data}
    end
end

And you'll get something like this:

 ["UninstallString",
  1,
  "\"C:\\WINDOWS\\$NtUninstallKB2393802$\\spuninst\\spuninst.exe\""],
 ["TSAware", 4, 1],
 ["NoModify", 4, 1],
 ["InstallDate", 1, "20110313"],
 ["Publisher", 1, "Microsoft Corporation"],
 ["NoRepair", 4, 1],
 ["HelpLink", 1, "http://support.microsoft.com?kbid=2393802"],
 ["URLInfoAbout", 1, "http://support.microsoft.com"],
 ["DisplayVersion", 1, "1"],
 ["ParentKeyName", 1, "OperatingSystem"],
 ["ParentDisplayName",

and so on.

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