如何在 Windows 中使用 Ruby 获取已安装应用程序的列表? [英] How to get list of installed applications using Ruby in Windows?
问题描述
我知道使用 wmi 查询 WIN32_product
可以读取已安装的应用程序列表,但该列表与控制面板下的添加/删除程序列表不同.另一种方法是在 Windows 注册表中读取 Software\Microsoft\Windows\CurrentVersion\Uninstall
?
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?
我正在使用以下几行 ruby 代码来做到这一点,但它不起作用
I am using the following few lines of ruby code to do that but it is not working
在这个例子中,我正在寻找一个名为 Branding 的软件(当我在 Windows 7 PC 中通过 regedit 时它会显示)
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'
这段代码有什么问题?
推荐答案
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'
Though beware of: 'Software\Wow6432Node\Windows\CurrentVersion\Uninstall'
这篇关于如何在 Windows 中使用 Ruby 获取已安装应用程序的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!