How to get list of installed applications using Ruby in Windows?
I know that using wmi query WIN32_product
one can read the list of installed applications but the list is different from add/remove pr开发者_如何学运维ogram 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?
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'
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
精彩评论