InstallShield Tips and Techniques

July 5, 2012

Checking return code from VBScript Custom Action

Filed under: Reference Materials — shieldmaster @ 9:20 pm

Recently I had the need to run a Custom Action in an older InstallShield Basic MSI project (version 10.5). The Custom Action would verify that a required application product was already installed – and at the correct version level. If either check failed, the Custom Action should return a negative return code and cause the installation to be cancelled.

I did not want to create the Custom Action using InstallScript since that version had the InstallScript Script Engine delivered as a separate MSI (ISScriptEngine.msi), and I wanted no additional MSI requirements. I decided on using VBScript for the Custom Action – but indicated earlier, I needed the VBScript function to return a value that can be used to abort the installation. I have used VBScript often in the past to retrieve CustomActionData and perform activities, but never had to need to issue a return code. Always I would create a VBScript Custom Action with the VBScript embedded in the Custom Action – but I could never could get this script technique to work.

Finally I created a VBScript Custom Action – but stored the VBScript in a .VBS script file.

Here is a snapshot of the Custom Action:

Note that I entered “CheckAgentVersion” in the Script Function line. Here is an extract of the VBScript:

Function  CheckAgentVersion

    Dim    sAgentVersion

       Const  cAgentBaseVersion = "11.01.0001.0000"


      'MsgBox "Running AgentLP CheckAgentVersion Custom Action"

       LogInfo "======== Running AgentLP CheckAgentVersion Custom Action =========="

       Set objShell = CreateObject("WScript.Shell")


       sAgentVersion = Session.Property("AGENT_VERSION")

       If sAgentVersion = "NOT FOUND" Then

        LogInfo "Agent was not installed!" 

        MsgBox "WARNING:  Agent was not installed!  Screen Capture Language Pack will abort!" 

        CheckAgentVersion = -1 


           LogInfo "Agent was installed - and version is: " & sAgentVersion   

           If Eval("sAgentVersion > cAgentBaseVersion") then

            LogInfo "Agent installed is proper version!"   

              CheckAgentVersion = 0 

            LogInfo "======== Exiting AgentLP CheckAgentVersion with return code of " & nReturn

            Exit Function 


              LogInfo "Agent installed is not the proper version!" 

            MsgBox "WARNING:  Agent installed is not the most current version, so Language Pack will abort!      

            CheckAgentVersion = -1                   

            LogInfo "======== Exiting AgentLP CheckAgentVersion with return code of " & nReturn   

            Exit Function

        End If     

    End If     

End Function


Function LogInfo(msg)

   dim rec

   Set rec = Session.Installer.CreateRecord(1)

   rec.StringData(0) = msg

   LogInfo = Session.Message(&H04000000, rec)

   'LogInfo is a VBScript function copyrighted (@2011) by Ian Linsdell

End Function


By setting the return code to the function name, it will be correctly interrogated by the Custom Action. Granted, you should never pop up a message dialog unless you query the “UserUI” property to see if they are running full dialogs (i.e., not silently). But this should give you a heads up on how to accomplish this.

Also a couple of notes about the VBScript function:

  1. A co-worker Ian Linsdell wrote the slick sub-function that allows you to write directly into the MSI log file. If you use this function, please continue to keep his copyrighted comment!
  2. The MSI Property “AGENT_VERSION” is a result of a System Search entry that looks for the registry entry that confirms the Agent was installed. Obviously if the installation was not found, the default value of “NOT FOUND” would be in the MSI Property.




Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: