Search code examples
vbscriptwixcustom-action

WiX - vbscript custom action with session.message function


I want to show a dialog to the user that says "this is going to be removed with this installation" and if "YES" or "OK" is pressed, then the installation can continue; otherwise, I want to abort it.

Therefore I have defined a custom action (run vbscript) like this:

<CustomAction Id="ShowUninstallInformationDlg" Impersonate="yes" Return="check" Execute="immediate" BinaryKey="ShowUninstallInformationDlg.vb" VBScriptCall=""/>
<Binary Id="ShowUninstallInformationDlg.vb" SourceFile="c:\myscripts\installer\ShowUninstallInformationDlg.vbs"/>
<InstallExecuteSequence>
  <Custom Action="ShowUninstallInformationDlg" After="FindRelatedProducts">NOT Installed AND NOT PATCH AND NOT MYPRODUCT_ANYVERSION=""</Custom>
</InstallExecuteSequence>

VBSCRIPT (ShowUninstallInformationDlg.vbs):

'ShowUninstallInformationDlg
Option Explicit

Dim text
Dim productName
Dim rec

productName = Session.Property("ProductName")
text = "The following installations are going to be removed with the installation of " & productName & ":"

If Session.Property("MYPRODUCT_ANYVERSION") <> "" Then
  text = text & "\n    * MyOtherProduct (any version)"
End If

Set rec = Session.Installer.CreateRecord(1)
rec.StringData(0) = text

Session.Message &H0B000034, rec

The kind "&H0B000034" I am using as "Session.Message" argument is from an example from the MSDN, see http://msdn.microsoft.com/en-us/library/windows/desktop/aa371672(v=vs.85).aspx.

Always the script is being executed I get the following error in my MSI log:

Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action ShowUninstallInformationDlg script error -2147467259, Msi API Error: Message,Kind,Record Line 19, Column 1,

I have searched google massively for examples using Session.Message, but with no succeeding results... Can anyone help? Thanks!


Solution

  • This script solved my issue, by using MsgBox instead of "Session.Message":

    'ShowUninstallInformationDlg
    Option Explicit
    
    const vbOKOnly           = 0    'OK button only
    const vbOKCancel         = 1    'OK and Cancel buttons
    const vbAbortRetryIgnore = 2    'Abort, Retry, and Ignore buttons
    const vbYesNoCancel      = 3    'Yes, No, and Cancel buttons
    const vbYesNo            = 4    'Yes and No buttons
    const vbRetryCancel      = 5    'Retry and Cancel buttons
    const vbCritical         = 16   'Critical Message icon
    const vbQuestion         = 32   'Warning Query icon
    const vbExclamation      = 48   'Warning Message icon
    const vbInformation      = 64   'Information Message icon
    const vbDefaultButton1   = 0    'First button is default
    const vbDefaultButton2   = 256  'Second button is default
    const vbDefaultButton3   = 512  'Third button is default
    const vbDefaultButton4   = 768  'Fourth button is default
    const vbApplicationModal = 0    'Application modal (the current application will not work until the user responds to the message box)
    const vbSystemModal      = 4096 'System modal (all applications wont work until the user responds to the message box)
    
    const vbOK     = 1 'OK was clicked
    const vbCancel = 2 'Cancel was clicked
    const vbAbort  = 3 'Abort was clicked
    const vbRetry  = 4 'Retry was clicked
    const vbIgnore = 5 'Ignore was clicked
    const vbYes    = 6 'Yes was clicked
    const vbNo     = 7 'No was clicked
    
    const msiDoActionStatusNoAction      = 0 '&H0
    const msiDoActionStatusSuccess       = 1 '&H1
    const msiDoActionStatusUserExit      = 2 '&H2
    const msiDoActionStatusFailure       = 3 '&H3
    const msiDoActionStatusSuspend       = 4 '&H4
    const msiDoActionStatusFinished      = 5 '&H5
    const msiDoActionStatusWrongState    = 6 '&H6
    const msiDoActionStatusBadActionData = 7 '&H7
    
    public function ShowMessage()
      Dim productName
      Dim text
      Dim buttons
      Dim result
    
      productName = Session.Property("ProductName")
      text = "The following installations are going to be removed from this computer by continuing the installation of " & productName & ":"
    
      If Session.Property("MYPRODUCT_ANYVERSION") <> "" Then
        text = text & chr(13) & chr(13) & "    * MyOtherProduct (any version)"
      End If 
    
      buttons = vbExclamation + vbOKCancel
      result = MsgBox(text, buttons, "Dependant Product Installations")
    
      If result = vbOK Then
        ShowMessage = msiDoActionStatusSuccess
      Else
        ShowMessage = msiDoActionStatusUserExit
      End If
    end function