SRG3006
SRG3006

Reputation: 457

What's wrong with my vbscript for MSI installer?

I'm writing a custom script to go with my installer so that users have the option to install a toolbar if they wish. Here's what the layout will look like:

http://i47.tinypic.com/2v92csl.png

And the code accompanying it:

' Set Executable
Set WshShell = CreateObject("WScript.Shell") 
' Set booleans for what features to enabled/disable
Dim Feature1 As Boolean
Dim Feature2 As Boolean
Dim Feature3 As Boolean
Dim Feature4 As Boolean
Feature1 = False
Feature2 = False
Feature3 = False
Feature4 = False

If Session.Property("RADIO") = "RadioFeatureA" Then
  Feature1 = True
  Feature2 = False
ElseIf Session.Property("RADIO") = "RadioFeatureB" Then
  Feature2 = True
  Feature1 = False
End If

' Set the checkbox1 feature if ticked
If Session.Property("CHECK1") = "install" Then 
  Feature3 = True
Else
  Feature3 = False
End If

' Set the checkbox2 feature if ticked
If Session.Property("CHECK2") = "install" Then
  Feature4 = True
Else
  Feature4 = False
End If

' Execute the file
If Feature1 = True Then
  WshShell.Run (""APPDIR\file.exe"" /SILENT /INSTALL)
ElseIf Feature2 = True And Feature3 = True Then
  WshShell.Run (""APPDIR\file.exe"" /SILENT)
ElseIf Feature2 = True And Feature4 = True Then
  WshShell.Run (""APPDIR\file.exe"" /SILENT)
ElseIf Feature2 = True And Feature3 = True And Feature4 = True Then
  WshShell.Run (""APPDIR\file.exe"" /SILENT /INSTALL)
End If

But for some reason the installer crashes. The code looks fine to me and executes externally?

Upvotes: 2

Views: 1462

Answers (1)

Bogdan Mitrache
Bogdan Mitrache

Reputation: 11023

I suspect the crash occurs when you try to launch your exdcutables. the reasons could be various, for example UAC rights. But whar caught my attention is how you are using APPDIR property. You should first get its value in a separate variable, then append the. executable name to the variable to get the correct path.

However, this will still not work because, I assume, you launch the script using a published event triggered by an action on your MSI dialog, that is before the files are installed, so your executables are not available.

From the screenshot I assume you are using Advanced Installer so you have two options to solve your problem:

  1. you can delete the files from Files view and add them again, this time using the "add temporary" file option, this will make them be available at the desired time. Temporary files also have attached an unique property, so you can use that to get their path, without being required ti construct it.
  2. you can add the setups as feature-based prerequisites, then go to Organization page and set install conditions on their features using your properties. Since normally the install conditions of a feature do not support using properties set from the MSI dialogs you will need to call the predefined custom action "update feature states" from the Next button of your dialog, so the feature states and install condtions are re-evaluated. This way you can eliminate your script, which is also not recommended to be used, antiviruses can flag your installer, vbscript engine might not work on the user machine, etc...

Upvotes: 2

Related Questions