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 FunctionThis 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))- 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")Regards,
Denis
FOLLOW US
Get the latest news in Application Packaging