Wednesday, May 22, 2013

Windows setup project vbs custom action return value

When I create a custom action use VB script. try rollback install.  return value from vbs custom action to installer. There is a little trick things .

we want the installer silent quit , (or pop our message)  not through exception.

I easy to find the msdn  about how to return value from custom action:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa371254(v=vs.85).aspx

Custom actions written in JScript or Visual Basic, Scripting Edition (VBScript) can call an optional function. These functions must return one of the values shown in the following table.
Return valueValueDescription
msiDoActionStatusNoAction0Action not executed.
msiDoActionStatusSuccessIDOK = 1Action completed successfully.
msiDoActionStatusUserExitIDCANCEL = 2Premature termination by user.
msiDoActionStatusFailureIDABORT = 3Unrecoverable error. Returned if there is an error during parsing or execution of the JScript or VBScript.
msiDoActionStatusSuspendIDRETRY = 4Suspended sequence to be resumed later.
msiDoActionStatusFinishedIDIGNORE = 5Skip remaining actions. Not an error.

Note that Windows Installer translates the return values from all actions when it writes the return value into the log file. For example, if the action return value appears as 1 (one) in the log file, this means that the action returned msiDoActionStatusSuccess. For more information about this translation see Logging of Action Return Values.

To return a value other than success from a script custom action, you must use a function target for the custom action. The target function is specified in the Target column of the CustomAction Table.
The following script example shows you how to return success or failure from a VBScript custom action.
Function MyVBScriptCA()

    If Session.Property("CustomErrorStatus") <> "0" Then
        'return error
        MyVBScriptCA = 3
        Exit Function
    End If

    ' return success
    MyVBScriptCA = 1
    Exit Function

End Function

If this VBScript were embedded in the Binary table of the installation package as MyCA.vbs, the CustomAction Table entry for the script would be the following:

ActionTypeSourceTarget
MyCustomAction6MyCA.vbsMyVBScriptCA



Build date: 11/30/2012

We know the most important thing is  :

To return a value other than success from a script custom action, you must use a function target for the custom action. The target function is specified in the Target column of the CustomAction Table.
The following script example shows you how to return success or failure from a VBScript custom action.

But how to set the target in customaction table ?

The vs2010 does not support  us set the function name in target table directly.

We have to open msi file (use ora edit or supperora )  ,  find custom action table.

 the problem is  Action and Source when  we open the custionaction table it is a numberstring create by vs2010. so , first we need from file table find the name.  then we put the function name in customaction table  target column .




No comments:

Post a Comment