使用 ruby 查询 Windows 上已安装的软件
我想查询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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你只是想了解该软件的完整信息,你可以使用这个:
你会得到类似这样的信息:
等等。
If you just want to know complete information about the software, you can use this:
And you'll get something like this:
and so on.