我想向用户显示一个对话框,上面写着"这将在本次安装中删除",如果按下"是"或"确定",则安装可以继续;否则,我想中止它。
因此,我定义了一个自定义操作(运行vbscript),如下所示:
<CustomAction Id="ShowUninstallInformationDlg" Impersonate="yes" Return="check" Execute="immediate" BinaryKey="ShowUninstallInformationDlg.vb" VBScriptCall=""/>
<Binary Id="ShowUninstallInformationDlg.vb" SourceFile="c:myscriptsinstallerShowUninstallInformationDlg.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的例子,但没有成功的结果。。。有人能帮忙吗?谢谢
我使用了以下内容,它正确地工作了
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
当在"添加/删除程序"中按下"删除"按钮时,不应该显示任何UI。或者,您可以禁用"删除"按钮并保持"更改"按钮处于启用状态。调用维护UI体验,该体验通常具有"修复|更改|删除"对话框。如果他们选择"删除"并按"下一步",您可以显示一个丰富的UI来询问您的问题。
这个脚本通过使用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
请参阅本文以获取类似的示例和解决方案。