10

I have an MSI installer in which I need to add or modify a short text property from the command-line.

This has to be done after the installer is built; I cannot modify the process that produces the installer in the first place. It also has to be executed headless from a script.

When I say "property," it could be an MSI property, a value that gets written to the registery at install-time, or any other mechanism that can get this short custom text into the installed application when it runs.

Jason Cohen
  • 81,399
  • 26
  • 107
  • 114

3 Answers3

13

Example VBScript that you could use to update (or add) a property post-build...

    Option Explicit

    Const MSI_FILE = "myfile.msi"


    Dim installer, database, view

    Set installer = CreateObject("WindowsInstaller.Installer")
    Set database = installer.OpenDatabase (MSI_FILE, 1)

    ' Update
    Set view = database.OpenView ("UPDATE Property SET Value = '" & myproperty & "' WHERE Property = 'MYPROPERTY'")

    ' .. or Add (Insert)
    Set view = database.OpenView ("INSERT INTO Property (Property, Value) VALUES ('MYPROPERTY', '" & myproperty & "')")
    view.Execute
    database.Commit

    Set database = Nothing
    Set installer = Nothing
    Set view = Nothing

For more information check out the Windows Installer SDK (part of the Windows SDK)

There's a bunch of example scripts that you can use from the command line to do various MSI manipulation tasks

For example WiRunSQL.vbs lets you execute arbitrary SQL against an MSI.

Józef Podlecki
  • 10,453
  • 5
  • 24
  • 50
saschabeaumont
  • 22,080
  • 4
  • 63
  • 85
  • 2
    Don't forget to update the package code in the Summary Information Stream when you change the package. While changing a property value is unlikely to cause actual problems even if you release multiple .msi files with different values, it's still something you need to do. – Michael Urman Oct 23 '09 at 13:27
  • I've only found that I need to update the Summary Information when creating transforms, any reason why you need to update for all changes? – saschabeaumont Oct 23 '09 at 23:47
  • I can't even update a variable with this script and get a runtime error "Variable is undefined". I have checked in Orca the property is defined. – AH. Mar 07 '13 at 13:35
  • I know this is old but modified to add database.Commit. – Shintaro Takechi Jun 08 '20 at 16:53
4
c:\> msiexec /i yourmsi.msi THEPROPERTYNAME=valueofproperty

For more information type msiexec at the commandline.

EDIT: or change the .msi file itself by using sql statements and updating the property in the properties table: http://msdn.microsoft.com/en-us/library/aa372021(VS.85).aspx http://msdn.microsoft.com/en-us/library/aa368568(VS.85).aspx

ZippyV
  • 12,540
  • 3
  • 37
  • 52
  • I thought that INSTALLS with a new property. I don't want to install, I need to MODIFY the MSI file. – Jason Cohen Oct 22 '09 at 19:17
  • 2
    I don't think this deserved the downvote, as this fit the criteria specified by OP's question. Post-build, is an MSI property, and is certainly "any other mechanism that can get this short custom text into the installed application when it runs." It's not altering the MSI itself, but doing this at the installer's runtime is effectively the same result. – SpellingD Mar 29 '12 at 18:54
1

This is to add to @saschabeaumont 's answer in '09. Currently using dotNet 4.0

Option Explicit

Const MSI_FILE = "myFilePath.msi"
Const PROPERTY_STRING_Value = "FooBar"

Dim installer, database, view

Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase (MSI_FILE, 1)

' Update
Set view = database.OpenView ("UPDATE Property SET Value = '" & PROPERTY_STRING_Value & "' WHERE Property = 'MYPROPERTY'")

' .. or Add (Insert)
Set view = database.OpenView ("INSERT INTO Property (Property, Value) VALUES ('MYPROPERTY', '" & PROPERTY_STRING_Value & "')")

view.Execute()
database.Commit()

Set database = Nothing
Set installer = Nothing
Set view = Nothing
asarenski
  • 46
  • 6