How to Get a List of Installed Programs in Windows using Ruby

If you're working on a project that involves getting information about the software installed on a Windows machine, you might find it useful to know how to programmatically retrieve this information using Ruby. One way to do this is by using the Windows Management Instrumentation (WMI) interface.

Caution: this will only find programms installed using windows installer. For other ways see here: "Please stop using win32product"

One gem that provides an easy way to interact with WMI is win32ole. With win32ole, you can connect to the WMI interface and execute queries to retrieve information about the installed programs on a Windows machine.

Here's an example of how you can use win32ole to get a list of installed programs, including their name, version, and vendor:

require 'win32ole'

wmi = WIN32OLE.connect("winmgmts://")
programs = wmi.ExecQuery("SELECT Name, Version, Vendor FROM Win32_Product")

programs.each do |program|
  puts "Name: #{program.Name}"
  puts "Version: #{program.Version}"
  puts "Vendor: #{program.Vendor}"
  puts ""
end

This code connects to the WMI interface and executes a query to retrieve the name, version, and vendor of each installed program.