2012-02-24 40 views
0

我想向用戶顯示一個對話框,指出「這將隨此安裝而被刪除」,如果按下「是」或「確定」,則安裝可以繼續;否則,我想放棄它。WiX - 使用session.message函數的vbscript自定義動作

所以我定義了一個自定義操作(運行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 

那種 「& H0B000034」 我用的是「 Session.Message「參數來自MSDN的示例,請參閱http://msdn.microsoft.com/en-us/library/windows/desktop/aa371672(v=vs.85).aspx

始終腳本正在執行我在MSI日誌中出現以下錯誤:

Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action ShowUninstallInformationDlg script error -2147467259, Msi API Error: Message,Kind,Record Line 19, Column 1,

我已搜查谷歌大量使用Session.Message的例子,但沒有成功的結果...誰能幫助?謝謝!

回答

0

這個腳本解決了我的問題,通過使用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 
+0

你不需要vbscript來做你正在做的事情。您可以使用您的屬性作爲ControlEvents的條件來顯示MSI對話框。在VBScript中執行此操作只會增加對已知脆弱技術的依賴性,從而使安裝程序的可靠性降低。 – 2012-02-27 13:29:01

+0

我已經試過了,但是我不能用對話框中斷UI鏈而不強迫它永遠退出!你有沒有工作的例子? – moik 2012-02-27 15:24:42

0

請參閱this發佈一個類似的例子和解決方案。

1

在添加/刪除程序中按下刪除按鈕時,您不應顯示任何UI。或者,您可以禁用「刪除」按鈕並保持啓用「更改」按鈕。這會調用通常具有Repair |的維護UI體驗更改|刪除對話框。如果他們選擇刪除,然後按下,您可以顯示一個豐富的用戶界面,提出您的問題

+0

嗨克里斯托弗,不,你讓我錯了。我想在初始安裝之前顯示該對話框,以讓用戶知道在安裝過程中會刪除其他一些產品。主要是我想要靈活地改變對話框中顯示的文本,這取決於我的設置的一些屬性,因此我使用了vbscript。 – moik 2012-02-27 06:48:36

+0

請參閱下面的評論。 – 2012-02-27 13:29:25

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