Scripting Question

VBScript to add New Feature in MSI Table

10/03/2016 1380 views
Hi All,

Need you help, i am creating a vbs script to add 1 new Feature if it does not exist in the MSI using the below script.

when i execute the script it fila to create feature, Please help.

Many Thanks

Const msiOpenDatabaseModeReadOnly = 0
Const msiOpenDatabaseModeTransact = 1
Const Audit = "Audit"
Const msiViewModifyInsert = 1
Const msiViewModifyUpdate = 2
Const msiViewModifyDelete = 6
Const msiViewModifyReplace = 4

Dim oInstaller : Set oInstaller = CreateObject("WindowsInstaller.Installer")
Dim oDatabase : Set oDatabase = oInstaller.OpenDatabase(WScript.Arguments(0),msiOpenDatabaseModeTransact) 

If oDatabase.TablePersistent("Feature") = 1 Then

'create a view of the registry we want to see
Dim sql : sql = "SELECT `Feature` FROM `Feature`"
Dim regView : Set regView = oDatabase.OpenView(sql)

'execute the query

'fetch the first row of data (if there is one!)
Dim regRecord : Set regRecord = regView.Fetch

'whilst we've returned a row and therefore regRecord is not Nothing
While Not regRecord Is Nothing
If regRecord.StringData(1) <> "Audit" Then

Dim test : test = "INSERT INTO Feature (`Feature`,`Title`,`Description`,`Display`,`Level`,`Directory_`,`Attributes`) VALUES ('Audit','Audit','Audit',3,1,'INSTALLDIR',0)"
Dim tempView : Set  tempView = oDatabase.OpenView(test)
End If
Set regRecord = regView.Fetch
End If


Set regView = Nothing
Set regRecord = Nothing
Set oDatabase = Nothing
Set oInstaller = Nothing
0 Comments   [ + ] Show comments


Community Chosen Answer

It would be an order of magnitude simpler to create a transform containing your new feature and its associated components.
Answered 10/03/2016 by: VBScab
Red Belt

All Answers

Have you downloaded the MSI SDK ?  There are MANY example vbscripts in it which can be used as a basis for what you are trying to do, including a couple of VBScripts which you could use from a batch file to edit your MSI tables.
Post a bit more information on what you are trying to achieve and maybe some more relevant answers can be provided.
Are you trying to edit your MSI tables during installation?  I've found that a handy solution to some issues.
Answered 10/10/2016 by: EdT
Red Belt

This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ