def discover_windows_executables(&block)
if RHC::Helpers.windows?
base_path = []
guessing_locations = []
if program_files = ENV['ProgramFiles']; program_files.present? && File.exists?(program_files)
base_path << program_files
end
begin
require 'win32ole'
WIN32OLE.new("Scripting.FileSystemObject").tap do |file_system|
file_system.Drives.each do |drive|
base_path << [
"#{drive.DriveLetter}:\\Program Files (x86)",
"#{drive.DriveLetter}:\\Program Files",
"#{drive.DriveLetter}:\\Progra~1",
"#{drive.DriveLetter}:"
]
end
end
rescue
end
executable_groups = []
base_path.flatten.uniq.each do |base|
executable_groups << yield(base)
end
unless executable_groups.empty?
length = executable_groups.first.length
for i in 1..length do
executable_groups.each do |group|
guessing_locations << group[i - 1]
end
end
end
guessing_locations.flatten.uniq.select {|cmd| File.exist?(cmd) && File.executable?(cmd)}
else
[]
end
end