Class: WindowsInstaller
- Inherits:
-
Hash
- Object
- Hash
- WindowsInstaller
- Defined in:
- lib/WindowsInstaller.rb
Constant Summary collapse
- @@default_options =
{mode: '/passive'}
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ WindowsInstaller
constructor
A new instance of WindowsInstaller.
- #install_msi(msi_file) ⇒ Object
- #msi_installed?(msi_file) ⇒ Boolean
- #product_code_installed?(product_code) ⇒ Boolean
- #uninstall_msi(msi_file) ⇒ Object
- #uninstall_product_code(product_code) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ WindowsInstaller
8 9 10 11 |
# File 'lib/WindowsInstaller.rb', line 8 def initialize( = {}) @@default_options.each { |key, value| self[key] = value } .each { |key, value| self[key] = value} end |
Class Method Details
.default_options(hash) ⇒ Object
13 14 15 |
# File 'lib/WindowsInstaller.rb', line 13 def self.(hash) hash.each { |key,value| @@default_options[key] = value } end |
Instance Method Details
#install_msi(msi_file) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/WindowsInstaller.rb', line 28 def install_msi(msi_file) raise "#{msi_file} does not exist!" unless(File.exists?(msi_file)) msi_file = File.absolute_path(msi_file).gsub(/\//, '\\') cmd = "msiexec.exe" cmd = "#{cmd} #{self[:mode]}" if(has_key?(:mode)) cmd = "#{cmd} /i #{msi_file}" msiexec(cmd) raise "Failed to install msi_file: #{msi_file}" unless(msi_installed?(msi_file)) end |
#msi_installed?(msi_file) ⇒ Boolean
17 18 19 20 |
# File 'lib/WindowsInstaller.rb', line 17 def msi_installed?(msi_file) info = msi_properties(msi_file) return product_code_installed?(info['ProductCode']) end |
#product_code_installed?(product_code) ⇒ Boolean
22 23 24 25 26 |
# File 'lib/WindowsInstaller.rb', line 22 def 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 |
#uninstall_msi(msi_file) ⇒ Object
41 42 43 44 45 |
# File 'lib/WindowsInstaller.rb', line 41 def uninstall_msi(msi_file) raise "#{msi_file} does not exist!" unless(File.exists?(msi_file)) info = msi_properties(msi_file) uninstall_product_code(info['ProductCode']) end |
#uninstall_product_code(product_code) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/WindowsInstaller.rb', line 47 def uninstall_product_code(product_code) raise "#{product_code} is not installed" unless(product_code_installed?(product_code)) cmd = "msiexec.exe" cmd = "#{cmd} #{self[:mode]}" if(has_key?(:mode)) cmd = "#{cmd} /x #{product_code}" msiexec(cmd) if(product_code_installed?(product_code)) properties = installed_properties(product_code) raise "Failed to uninstall #{properties['InstalledProductName']} #{properties['VersionString']}" end end |