Skip to content

Commit

Permalink
updated Tasks to get MSI Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven authored and Steven committed Jan 10, 2020
1 parent 2c3e757 commit 8163ff2
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
47 changes: 44 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [{
"tasks": [
{
"label": "Initialize Environment",
"type": "shell",
"command": [
Expand Down Expand Up @@ -84,9 +85,30 @@
"reevaluateOnRerun": false
},
"problemMatcher": []
},
{
"label": "Get MSI Codes",
"type": "shell",
"command": [
"./tasks/Get-MSICode.ps1 -Path '${input:MSIFile}' -Property ${input:MSIProperty}"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"runOptions": {
"reevaluateOnRerun": false
},
"problemMatcher": []
}
],
"inputs": [{
"inputs": [
{
"id": "buildType",
"type": "pickString",
"description": "Where's the location of the install media?",
Expand All @@ -99,7 +121,26 @@
{
"type": "promptString",
"id": "user",
"description": "Enter the global admin account UPN for deployment.."
"description": "Enter the domain admin account UPN for deployment.."
},
{
"type": "promptString",
"id": "MSIFile",
"description": "Full path to the MSIFile Please"
},
{
"id": "MSIProperty",
"type": "pickString",
"description": "Which MSI Property do you want returned?",
"options": [
"ProductCode",
"ProductVersion",
"ProductName",
"Manufacturer",
"ProductLanguage",
"FullVersion"
],
"default": "ProductCode"
}
]
}
40 changes: 40 additions & 0 deletions tasks/Get-MSICode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[System.IO.FileInfo]$Path,

[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[ValidateSet("ProductCode", "ProductVersion", "ProductName", "Manufacturer", "ProductLanguage", "FullVersion")]
[string]$Property
)
Process {
try {
# Read property from MSI database
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($Path.FullName, 0))
$Query = "SELECT Value FROM Property WHERE Property = '$($Property)'"
$View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
$Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)

# Commit database and close view
$MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null)
$View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null)
$MSIDatabase = $null
$View = $null

# Return the value
Set-Clipboard $Value
return "$Value copied to clipboard"
}
catch {
Write-Warning -Message $_.Exception.Message ; break
}
}
End {
# Run garbage collection and release ComObject
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($WindowsInstaller) | Out-Null
[System.GC]::Collect()
}

0 comments on commit 8163ff2

Please sign in to comment.