Reputation: 4697
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?
Upvotes: 1
Views: 1267
Reputation: 24627
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.
Upvotes: 3