【问题标题】:WiX - vbscript custom action with session.message functionWiX - 带有 session.message 功能的 vbscript 自定义操作
【发布时间】:2012-02-24 11:19:09
【问题描述】:

我想向用户显示一个对话框,上面写着“此安装将被删除”,如果按下“是”或“确定”,则可以继续安装;否则,我想中止它。

因此我定义了一个自定义操作(运行 vbscript),如下所示:

<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

我用作“Session.Message”参数的那种“&H0B000034”来自 MSDN 的一个示例,请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/aa371672(v=vs.85).aspx

总是在执行脚本我在我的 MSI 日志中收到以下错误:

错误 1720。此 Windows 安装程序包有问题。无法运行完成此安装所需的脚本。请联系您的支持人员或软件包供应商。自定义操作 ShowUninstallInformationDlg 脚本错误 -2147467259,Msi API 错误:消息,种类,记录第 19 行,第 1 列,

我已经在谷歌上大量搜索了使用 Session.Message 的示例,但没有成功的结果......有人可以帮忙吗?谢谢!

【问题讨论】:

    标签: vbscript wix custom-action


    【解决方案1】:

    我已经使用了以下并且它工作正常

    Session.Message &H04000000, rec 
    

    请看我为它写的vbs

      Sub LogMessage(msg)
    
          Dim rec
          Set rec = Session.Installer.CreateRecord(1)
          rec.StringData(0) = "Custom Message : " & msg
          Session.Message &H04000000,rec
    
      End Sub
    

    【讨论】:

      【解决方案2】:

      当在“添加/删除程序”中按下“删除”按钮时,您不应显示任何 UI。或者,您可以禁用删除按钮并启用更改按钮。这会调用通常具有修复 | 的维护 UI 体验。改变 |删除对话框。如果他们选择删除并按下一步,您可以显示一个丰富的 UI 来询问您的问题。

      【讨论】:

      • 嗨克里斯托弗,不,你误会了。我想在初始安装之前显示该对话框,让用户知道在安装过程中将删除一些其他产品。主要是我希望根据设置的某些属性灵活地更改对话框中显示的文本,因此我使用了 vbscript。
      【解决方案3】:

      这个脚本通过使用 MsgBox 而不是“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
      

      【讨论】:

      • 你不需要 vbscript 来做你正在做的事情。您可以使用您的属性作为 ControlEvents 的条件来显示 MSI 对话框。在 VBScript 中这样做只会增加对已知脆弱技术的依赖,从而降低安装程序的可靠性。
      • 我已经尝试过了,但是我无法通过对话框中断 UI 链而不强制它始终退出!你有一个可行的例子吗?
      【解决方案4】:

      请参阅this 帖子以获取类似示例和解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-22
        • 2011-02-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多