Created
November 6, 2017 03:29
-
-
Save zhilich/522c33f863bb8e0a18ff80657b88315b to your computer and use it in GitHub Desktop.
Installing MSI several times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory=$false)][string]$Instance | |
) | |
[string]$DefaultInstance = "MyProduct_MSI" | |
if ($Instance) { | |
Write-Host "Copying installer to $($Instance).msi" | |
Copy-Item "MyProduct_MSI.msi" "$($Instance).msi" | |
$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider | |
$utf8 = new-object -TypeName System.Text.UTF8Encoding | |
$hash = (new-object -TypeName System.Guid -ArgumentList @(,$md5.ComputeHash($utf8.GetBytes($Instance)))).ToString().ToUpper() | |
Write-Host "Product code: $($hash)" | |
Write-Host "Injecting product code into $($Instance).msi" | |
Invoke-Expression -Command:"cscript wirunsql.vbs $($Instance).msi ""UPDATE Property SET Value='{$($hash)}' WHERE Property='ProductCode'""" | |
Invoke-Expression -Command:"cscript wirunsql.vbs $($Instance).msi ""UPDATE Property SET Value='MyProduct ($($Instance))' WHERE Property='ProductName'""" | |
Invoke-Expression -Command:"cscript wirunsql.vbs $($Instance).msi ""UPDATE Property SET Value='{$($hash)}' WHERE Property='UpgradeCode'""" | |
Invoke-Expression -Command:"cscript wisuminf.vbs $($Instance).msi Revision='{$($hash)}'" | |
} | |
else { | |
$Instance = $DefaultInstance | |
} | |
Write-Host "Launching installer package..." | |
Invoke-Expression -Command:"msiexec /i $($Instance).msi" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment