Tuesday, September 09, 2008

Using VBScript to Set Properties in MSI

We can easily use Set Property Custom Action to set Windows Installer Property, but sometimes we wish to set the property directly in VbScript, specially if we are taking an input from a user through VBScript. Hope this tip helps.

To set property through VBScript we can use "Session" object like:

Session.Property("ALLUSERS")="1"

or we can directly use Property keyword like:

Property("REBOOT")="ReallySuppress"

The only catch here is that we cannot set INSTALLDIR property through the above method as the package uses Directory table to store the value of INSTALLDIR. We need to write the below VBScript to set INSTALLDIR:

dim instpath

instpath = "C:\newpath\newfolder"

Session.TargetPath("INSTALLDIR")=instpath

Remember to place this Custom Action after CostFinalize if you are changing the value of INSTALLDIR property in UI Sequence.

6 comments:

SimB said...

Big... big thanks for the important tip about the order of sequence. Change the property "After CostFinalize in the UI sequence". I have looking so long to understand why I couldn't change my property correctly. Now its working perfectly

Looking 10-20 forums...nothing about that. That little tip saved me lots of time (5 stars*)

daverost said...

I have a .msi file that I want to run using a vbs script and I want to pass the Install directory to the file before/while it runs. What code would I use to do that. Thanks for the help, Im very new at all this!

daverost said...

Hi,

Firstly let me say I am very new in this area.

I have created a .msi file using advanced installer. I want to pass the INSTALLDIR from a vbs script before/while the installer runs. Again I'm quite nexperienced, an explanation of how this could be done would be highly appreciated!

Piyush Nasa said...

Just pass INSTALLDIR= as a parameter to run MSI.
You can use the code to run exe to run msi..
Run msiexec.exe YourMSI.MSI INSTALLDIR= /qb
and run this.
If you need more help let me know.

daverost said...

Hi Piyush, thanks for the help.

This is what is have now, running as a .vbs script. It is however not working. Any ideas? It opens a opens a window saying "Configuring edudrive" but then doesn't open the GUI or run the .msi.

Thanks again!

dim myvar

myvar="D:\EduDrive"

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "msiexec.exe /I F:\eduinstaller.msi INSTALLDIR=myvar /qb"

Piyush Nasa said...

By Default, the RootDrive points to the drive which has the most disk space available. You will have to change the ROOTDRIVE Property in your package to D:\
You can pass ROOTDRIVE=D:\ in commandline parameter and then INSTALLDIR like you have done.
I am not sure F: will work as the MSI location. you will have to give the complete path.