-
Notifications
You must be signed in to change notification settings - Fork 26
/
Install-Java8.ps1
44 lines (36 loc) · 1.5 KB
/
Install-Java8.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
param (
[Parameter(Mandatory=$true)]
[IO.FileInfo]
$MSI
, [string]
$Name
)
if (!(Test-Path $MSI.FullName)) {
throw "File '{0}' does not exist" -f $MSI.FullName
}
# All this just the get the version string from the MSI
try {
$windowsInstaller = New-Object -com WindowsInstaller.Installer
$database = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase", "InvokeMethod", $Null,
$windowsInstaller, @($MSI.FullName, 0)
)
$q = "SELECT Value FROM Property WHERE Property = 'ProductVersion'"
$View = $database.GetType().InvokeMember(
"OpenView", "InvokeMethod", $Null, $database, ($q)
)
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$record = $View.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $View, $Null )
[version]$UpdateNumber = $record.GetType().InvokeMember( "StringData", "GetProperty", $Null, $record, 1 )
} catch {
throw "Failed to get MSI file version: {0}." -f $_
}
# Now the installed version string, if any. win32_product is super slow :(
# Could maybe check the registry for this key. Need to deal with different x86 and x64 paths.
[version]$Version = Get-WmiObject -Class Win32_Product -Filter "Name Like '$Name%'" |
Select -ExpandProperty Version
# Compare versions of [version] type and install if needed
if($Version -lt $UpdateNumber){
"run install"
#Invoke-Expression "msiexec /i $MSI AUTOUPDATE=0 REBOOT=0 WEB_JAVA=1 /qn /lv C:\Install-$Name.log"
}