Class: Wixgem::WindowsInstaller
- Inherits:
-
Object
- Object
- Wixgem::WindowsInstaller
- Defined in:
- lib/WindowsInstaller.rb
Class Method Summary collapse
- .dump_info(product_name) ⇒ Object
- .install(msi_file) ⇒ Object
- .msi_info(installer, msi_file) ⇒ Object
- .msi_installed?(msi_file) ⇒ Boolean
- .product_code_from_product_name(product_name, installer = nil) ⇒ Object
- .product_code_installed?(product_code) ⇒ Boolean
- .product_info(installer, code) ⇒ Object
- .product_name_installed?(product_name) ⇒ Boolean
- .uninstall(msi_file) ⇒ Object
- .uninstall_product_code(product_code) ⇒ Object
- .uninstall_product_name(product_name) ⇒ Object
- .version_from_product_name(product_name) ⇒ Object
Class Method Details
.dump_info(product_name) ⇒ Object
98 99 100 101 102 |
# File 'lib/WindowsInstaller.rb', line 98 def self.dump_info(product_name) installer = WIN32OLE.new('WindowsInstaller.Installer') properties = product_info(installer, product_code_from_product_name(product_name, installer)) properties.each { |id, value| puts "#{id}: #{value}" } end |
.install(msi_file) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/WindowsInstaller.rb', line 6 def self.install(msi_file) raise "#{msi_file} does not exist!" unless(File.exists?(msi_file)) msi_file = msi_file.gsub(/\//, '\\') raise "#{msi_file} is already installed" if(WindowsInstaller.msi_installed?(msi_file)) execute("msiexec.exe /quiet /i #{msi_file}") end |
.msi_info(installer, msi_file) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/WindowsInstaller.rb', line 85 def self.msi_info(installer, msi_file) raise 'Windows installer cannot be nil' if(installer.nil?) hash = Hash.new # known product keywords found on internet. Would be nice to generate. %w[Language PackageCode Transforms AssignmentType PackageName InstalledProductName VersionString RegCompany RegOwner ProductID ProductIcon InstallLocation InstallSource InstallDate Publisher LocalPackage HelpLink HelpTelephone URLInfoAbout URLUpdateInfo InstanceType].sort.each do |prop| value = installer.ProductInfo(code, prop) hash[prop] = value unless(value.nil? || value == '') end return hash end |
.msi_installed?(msi_file) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/WindowsInstaller.rb', line 30 def self.msi_installed?(msi_file) info = msi_records(msi_file) result = product_code_installed?(info['ProductCode']) return result end |
.product_code_from_product_name(product_name, installer = nil) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/WindowsInstaller.rb', line 63 def self.product_code_from_product_name(product_name, installer = nil) installer = WIN32OLE.new('WindowsInstaller.Installer') if(installer.nil?) installer.Products.each { |prod_code| name = installer.ProductInfo(prod_code, "ProductName") return prod_code if (product_name == name) } raise "Failed to find product code for product: #{product_name}" end |
.product_code_installed?(product_code) ⇒ Boolean
45 46 47 48 49 |
# File 'lib/WindowsInstaller.rb', line 45 def self.product_code_installed?(product_code) installer = WIN32OLE.new('WindowsInstaller.Installer') installer.Products.each { |installed_product_code| return true if (product_code == installed_product_code) } return false end |
.product_info(installer, code) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/WindowsInstaller.rb', line 72 def self.product_info(installer, code) raise 'Windows installer cannot be nil' if(installer.nil?) hash = Hash.new # known product keywords found on internet. Would be nice to generate. %w[Language PackageCode Transforms AssignmentType PackageName InstalledProductName VersionString RegCompany RegOwner ProductID ProductIcon InstallLocation InstallSource InstallDate Publisher LocalPackage HelpLink HelpTelephone URLInfoAbout URLUpdateInfo InstanceType].sort.each do |prop| value = installer.ProductInfo(code, prop) hash[prop] = value unless(value.nil? || value == '') end return hash end |
.product_name_installed?(product_name) ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/WindowsInstaller.rb', line 36 def self.product_name_installed?(product_name) installer = WIN32OLE.new('WindowsInstaller.Installer') installer.Products.each { |prod_code| name = installer.ProductInfo(prod_code, "ProductName") return true if (product_name == name) } return false end |
.uninstall(msi_file) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/WindowsInstaller.rb', line 13 def self.uninstall(msi_file) raise "#{msi_file} does not exist!" unless(File.exists?(msi_file)) info = msi_records(msi_file) uninstall_product_code(info['ProductCode']) end |
.uninstall_product_code(product_code) ⇒ Object
25 26 27 28 |
# File 'lib/WindowsInstaller.rb', line 25 def self.uninstall_product_code(product_code) raise "#{product_code} is not installed" unless(product_code_installed?(product_code)) execute("msiexec.exe /quiet /x #{product_code}") end |
.uninstall_product_name(product_name) ⇒ Object
20 21 22 23 |
# File 'lib/WindowsInstaller.rb', line 20 def self.uninstall_product_name(product_name) raise "#{product_name} is not installed" unless(product_name_installed?(product_name)) uninstall_product_code(product_code_from_product_name(product_name)) end |
.version_from_product_name(product_name) ⇒ Object
57 58 59 60 61 |
# File 'lib/WindowsInstaller.rb', line 57 def self.version_from_product_name(product_name) installer = WIN32OLE.new('WindowsInstaller.Installer') info = product_info(installer, product_code_from_product_name(product_name, installer)) return info['VersionString'] end |