我想向用户显示一个对话框,说明“这将通过此安装删除”,如果按下“是”或“确定”,则安装可以继续;否则,我想中止它。
因此我定义了一个自定义操作(运行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
我使用的“&amp; H0B000034”作为“Session.Message”参数来自MSDN的示例,请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/aa371672(v=vs.85).aspx。
始终正在执行脚本我的MSI日志中出现以下错误:
错误1720.此Windows Installer程序包存在问题。无法运行此安装所需的脚本。请联系您的支持人员或包装供应商。自定义操作ShowUninstallInformationDlg脚本错误-2147467259,Msi API错误:消息,种类,记录行19,第1列,
我使用Session.Message大量搜索谷歌示例,但没有取得任何成功......有人可以帮忙吗?谢谢!
答案 0 :(得分:4)
我使用过以下功能正常
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
答案 1 :(得分:1)
在“添加/删除程序”中按下“删除”按钮时,不应显示任何UI。或者,您可以禁用“删除”按钮并启用“更改”按钮。这会调用通常具有Repair |的维护UI体验改变|删除对话框。如果他们选择删除并按下下一步,则可以显示一个丰富的用户界面询问您的问题。
答案 2 :(得分:1)
这个脚本通过使用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
答案 3 :(得分:0)
有关类似示例和解决方案,请参阅this帖子。