PDA

View Full Version : Message box from custom action



Diablo_m
11-21-2008, 09:40 AM
Hi.

I need to show a message box with yes/no buttons and some text from custom action. My installation is MSI project and I wanted this message box to be shown from VB script. I googled for the samples but found nothing.

So is it possible to show standart Windows message box from VB code or some other custom action? Please give me a sample code, 'cause I'm nube in VB :(

esiemiat
11-21-2008, 04:20 PM
It is possible to use the MsgBox command in a VBScript CA but you have to account for the UILevel when showing the message box so as to not show it during a silent installation.

I use the Session.Message method to show messages as it handles the UILevel for you. The following code shows an informative message either to the log or screen depending on the UIlevel. Other codes can be used instead of &H03000000 to show an error or warning message.



Set hMsgRecord = Installer.CreateRecord(0)
hMsgRecord.StringData(0) = "Test message"
Session.Message &H03000000, hMsgRecord
Set hMsgRecord = nothing

Diablo_m
12-01-2008, 09:53 AM
It is possible to use the MsgBox command in a VBScript CA but you have to account for the UILevel when showing the message box so as to not show it during a silent installation.

I use the Session.Message method to show messages as it handles the UILevel for you. The following code shows an informative message either to the log or screen depending on the UIlevel. Other codes can be used instead of &H03000000 to show an error or warning message.



Set hMsgRecord = Installer.CreateRecord(0)
hMsgRecord.StringData(0) = "Test message"
Session.Message &H03000000, hMsgRecord
Set hMsgRecord = nothing


Thank you for reply. This code is good, but it does not solve one of my problems - the message should be localizable. How to get the message text from the resources?

esiemiat
12-01-2008, 10:39 AM
To localize the message you will either need to use the Error table or a localized property.

More information about both options can be found in the help library. However, I included a sample from one of my installs that uses the error table.



Set hMsgRecord = Installer.CreateRecord(2)
hMsgRecord.IntegerData(1) = 25002 'Error message number in error table.
hMsgRecord.StringData(2) = sNetworkDir ' Replaces [2] in error message.
Session.Message msiMessageTypeError, hMsgRecord
Set hMsgRecord = nothing


Here is the localizable message listed in the error table. Anything listed in {{}} will only be printed to the log file.


The specified Pages network folder is not valid.{{Value='[2]'}}

Diablo_m
12-03-2008, 05:16 AM
Thank you, you helped me much!