We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Launch file or open URL conditionally

Hi,

Suppose you need to ask the user before launching an external program or opening a web page. For example, when the user uninstalls your application, you might want to conditionally open a web page where the user would provide a reason for uninstalling the program.

This can be done using 2 Custom Actions: the first CA will ask the user and set a Property according to his answer and the second one will be conditioned by the value of that Property.

I shall explain the process for the example given above. These are the required steps:

1. Create a new text file ("AskUser.vbs") and copy the following code into it:

Code: Select all

Ask("Question... ?"), "ANSWER"

Function Ask(strPrompt,strProperty)
  Const msiMessageTypeUser = &H03000000
  Dim ans, strAns
  
  Set record = Session.Installer.CreateRecord(0)
  record.StringData(0) = strPrompt
  ans = Session.Message(msiMessageTypeUser + vbYesNo + vbQuestion, record)
  
  If ans = vbYes Then
    strAns = "yes"
  Else
    strAns = "no"
  End If
  
  Session.Property(strProperty) = strAns
End Function
You need to change the parameters passed to the "Ask" function: the question string and, if necessary, the name of the Property that will hold the user's answer - I have used "ANSWER".

This script uses the "Message" method of the "Session" object rather than a simple "MsgBox" function. This ensures that the message box is modal.


2. Switch to the Custom Actions page and create a New Attached Custom Action scheduled on the "Uninstall" stage. Select the VBScript you have created previously. Set the following properties for this CA:
- Function Name: (It must be blank)
- Execution Properties: "Synchronous execution, ignore return code"
- Execution Options: "Immediate execution" (not "Deferred")
- Execution Condition:

Code: Select all

(REMOVE="ALL" AND (NOT UPGRADINGPRODUCTCODE))
3. Add the Predefined Custom Action "Launch File or Open URL" on the "Uninstall" stage. Set the following properties for this CA:
- Command Line: http://www.your-site.com/uninstall.htm
- Execution Properties: Asynchronous Execution, do not wait for return.
- Execution Options: "Deferred"
- Execution Condition:

Code: Select all

(REMOVE="ALL" AND (NOT UPGRADINGPRODUCTCODE)) AND (ANSWER = "yes")
Hope this helps.

Regards,
Denis
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
DanC
Posts: 1
Joined: Mon Feb 27, 2006 9:26 am

It looks like the dialog with the question is displayed at the beginning of the uninstall process, while the opening of the web page is done at the end.

Is it possible to schedule the VBS script at the end of the uninstall? For instance can it is marked as deferred, and the web page opened directly from the script? (not using viewer.exe)
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,

This VBScript CA accesses the "ANSWER" Property and thus it cannot be "Deferred".

However:
1. It is possible to schedule both the VBScript Custom Action and the predefined "viewer.exe" CA at the end of the (un)installation process.

2. It is possible to open the URL from within the script so that it will not be necessary to use the predefined "Launch File or Open URL" Custom Action.

Detailed explanation for both of the above cases follows:

1. Move both Custom Actions on the "InstallFinalize" stage. Note that the "viewer.exe" CA will be set automatically to "Immediate". All the other properties remain the same.

2. Move the VBScript CA on the "InstallFinalize" stage, delete the "viewer.exe" CA. Replace the script code with the following:

Code: Select all

AskThenOpenURL("Question... ?")

Function AskThenOpenURL(strPrompt)
  Const msiMessageTypeUser = &H03000000
  Dim ans
  
  Set record = Session.Installer.CreateRecord(0)
  record.StringData(0) = strPrompt
  ans = Session.Message(msiMessageTypeUser + vbYesNo + vbQuestion, record)
  
  If ans = vbYes Then
    OpenURL("http://www.your-site.com/uninstall.htm") 
  End If
End Function

Function OpenURL(strURL)
   Set WshShell = CreateObject("WScript.Shell")
   ret = WshShell.Run(strURL, 1, False)
End Function
Let me know if you have any other questions.

Regards,
Denis
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”