Created
January 8, 2017 08:08
-
-
Save kemokemo/c56e297fb965e148746281a2bdfd5403 to your computer and use it in GitHub Desktop.
Get value of specified property from a msi file.
This file contains 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
Option Explicit | |
''' Main Function | |
' Arguments | |
Dim msiPath | |
Dim propertyName | |
GetArguments() | |
' Open database to access msi file's property | |
Dim installer | |
Set installer = WScript.CreateObject("WindowsInstaller.Installer") | |
Dim database | |
Set database = installer.OpenDatabase(msiPath, 0) ' Read only | |
' Get value from property name | |
Dim value | |
value = GetPropertyValue(database, propertyName) | |
WScript.Echo(value) | |
database.Commit | |
Set database = Nothing | |
Set installer = Nothing | |
WScript.Quit(0) | |
''' Sub Functions ''' | |
' Check and get arguments | |
Sub GetArguments() | |
Dim oArgs | |
Set oArgs = WScript.Arguments | |
If oArgs.Count < 2 Then | |
WScript.Echo("Usage:") | |
WScript.Echo(" msipropety.vbs arg1 arg2") | |
WScript.Echo(" arg1: path to msi file") | |
WScript.Echo(" arg2: property name") | |
Wscript.Quit(-1) | |
End If | |
msiPath = oArgs(0) | |
propertyName = oArgs(1) | |
End Sub | |
' Get value from property table | |
Function GetPropertyValue(database, name) | |
Dim query | |
query = "SELECT Value FROM Property WHERE Property='" & name & "'" | |
Dim view | |
Set view = database.OpenView(query) | |
view.Execute | |
Dim record | |
Set record = view.Fetch | |
GetPropertyValue = record.StringData(1) | |
Set record = Nothing | |
Set view = Nothing | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment