WindowsInstaller 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/WindowsInstaller.rb +37 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e31fcaccb5e69f2740c980719dc8e3d6e562a7a2
4
- data.tar.gz: 2499e97a98c149a8e5dde4496b72bc5310df87ee
3
+ metadata.gz: 359306bd86ef11f6e8f78c2b2d6d2420a97e72d0
4
+ data.tar.gz: bb63a1eafc15aafaa86b4352610d26a5dbdc65c2
5
5
  SHA512:
6
- metadata.gz: f547f75af0f2f1fec05a38f9f6baf98362d8d59d8edc4c7ceeb049f26f2a3c50367efc0a88679675e3c2856af6d9031972924d9215d7123c693f6d2104e1849c
7
- data.tar.gz: 5e5c0cb29ffdd11b546fe351bea8de693a5e304ce57871908d5d864ab978083a81645ac48ae770ef1b8c3ae148296328aa7b3a090f67f21f641cb6beba7359f2
6
+ metadata.gz: e3d628800ef1b2d8359f2f768fa47aadaabe006958e9f369b7698b7cfab7c7700e531174b9f6beb27eb2c6303a28417f00e5a617fad9d1bb82ee7dfce302fce7
7
+ data.tar.gz: 290b44b8290aa62f6911b1638de1494ab6f40d604951e58ee526f1178aa9fbd91810def216db3ce8c58e9db831600683127bd8e94dbe57ae5adf0d099ff24684
@@ -35,6 +35,7 @@ class WindowsInstaller < Hash
35
35
  cmd = "#{cmd} /i #{msi_file}"
36
36
 
37
37
  msiexec(cmd)
38
+ raise "Failed to install msi_file: #{msi_file}" unless(msi_installed?(msi_file))
38
39
  end
39
40
 
40
41
  def uninstall_msi(msi_file)
@@ -45,14 +46,32 @@ class WindowsInstaller < Hash
45
46
 
46
47
  def uninstall_product_code(product_code)
47
48
  raise "#{product_code} is not installed" unless(product_code_installed?(product_code))
48
-
49
+
49
50
  cmd = "msiexec.exe"
50
51
  cmd = "#{cmd} #{self[:mode]}" if(has_key?(:mode))
51
52
  cmd = "#{cmd} /x #{product_code}"
52
53
  msiexec(cmd)
54
+ if(product_code_installed?(product_code))
55
+ properties = installed_properties(product_code)
56
+ raise "Failed to uninstall #{properties['InstalledProductName']} #{properties['VersionString']}"
57
+ end
53
58
  end
54
59
 
55
60
  private
61
+ def installed_properties(product_code)
62
+ installer = WIN32OLE.new('WindowsInstaller.Installer')
63
+
64
+ hash = Hash.new
65
+ # known product keywords found on internet. Would be nice to generate.
66
+ %w[Language PackageCode Transforms AssignmentType PackageName InstalledProductName VersionString RegCompany
67
+ RegOwner ProductID ProductIcon InstallLocation InstallSource InstallDate Publisher LocalPackage HelpLink
68
+ HelpTelephone URLInfoAbout URLUpdateInfo InstanceType].sort.each do |prop|
69
+ value = installer.ProductInfo(product_code, prop)
70
+ hash[prop] = value unless(value.nil? || value == '')
71
+ end
72
+ return hash
73
+ end
74
+
56
75
  def msi_properties(msi_file)
57
76
  raise "#{msi_file} does not exist!" unless(File.exists?(msi_file))
58
77
 
@@ -82,22 +101,30 @@ class WindowsInstaller < Hash
82
101
  end
83
102
 
84
103
  def msiexec(cmd)
85
- cmd = "runas /noprofile /savecred /user:#{self[:administrative_user]} \"#{cmd}\"" if(self.has_key?(:administrative_user))
86
-
87
104
  cmd_options = { echo_command: false, echo_output: false} unless(self[:debug])
88
-
105
+ if(self.has_key?(:administrative_user))
106
+ msiexec_admin(cmd, cmd_options)
107
+ else
108
+ command = CMD.new(cmd, cmd_options)
109
+ command.execute
110
+ end
111
+ end
112
+
113
+ def msiexec_admin(cmd, options)
114
+ cmd = "runas /noprofile /savecred /user:#{self[:administrative_user]} \"#{cmd}\""
115
+
89
116
  pre_execute = Sys::ProcTable.ps
90
117
 
91
- pre_pids = {}
92
- pre_execute.each { |ps| pre_pids[ps.pid] = ps }
118
+ pre_pids = []
119
+ pre_execute.each { |ps| pre_pids << ps.pid }
93
120
 
94
- command = CMD.new(cmd, cmd_options)
121
+ command = CMD.new(cmd, options)
95
122
  command.execute
96
-
123
+
97
124
  msiexe_pid = 0
98
- post_execute = Sys::ProcTable.ps
125
+ post_execute = Sys::ProcTable.ps
99
126
  post_execute.each do |ps|
100
- msiexe_pid = ps.pid if((ps.name.downcase == "msiexec.exe") && !pre_pids.has_key?(ps.pid))
127
+ msiexe_pid = ps.pid if((ps.name.downcase == "msiexec.exe") && pre_pids.index(ps.pid).nil?)
101
128
  end
102
129
 
103
130
  if(msiexe_pid != 0)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: WindowsInstaller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Marshall