Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Jscript sample with a messagebox


7 replies to this topic

Johannes John

Johannes John
  • Full Members
  • 223 posts

Posted 01 October 2001 - 10:44

Hello,

does someone can send me just a simple jscript with a messagebox, that doesn't end with a 2740.
A js-file or a script to include in the CA will be fine.

Many thanks in advance.
Johannes


grahamm

grahamm
  • Members
  • 15 posts

Posted 18 October 2001 - 17:46

I don't think you can use alert or WScript.Echo inside custom actions - it would rather interrupt the flow of things I guess.

You can send messages to the installer and get it to display a message box for you though... Check out Session.Message in the help. It's a bit fiddly but you can get error, warning or whatever dialogs out if you want.

If you need more information, I can probably knock something up for you if you let me know what you need.

Graham


Johannes John

Johannes John
  • Full Members
  • 223 posts

Posted 19 October 2001 - 12:51

Thank you Graham!

It's like the first steps in C++, when you write a program that writes "Hello world!" on the screen.
I wish, I had a js-file, that's running, not getting an 2740 error and I'm getting a reaction on the screen.
Perhaps getting a string out of a property and showing this string in a messagebox.

That would be great, many thanks in advance!
Johannes


Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 19 October 2001 - 15:49

In VB Script you would do the following to display the value of INSTALLDIR:

MsgBox Session.Property("INSTALLDIR")

I guess in JScript it would be quite similar.


grahamm

grahamm
  • Members
  • 15 posts

Posted 22 October 2001 - 10:29

You would think it would be that easy wouldn't you?

Unfortunately J[ava]Script was not designed with Win32 as a sole target like VBScript and so no UI features are included natively in the language at all. It is expected that the code will run in some kind of context that provides objects to do this work - hence the window.alert() method in DHTML, and the WScript.Echo() method in the Windows Scripting Host.

In Windows Installer the only context we have available is the Session object. Fortunately, we can persuade this object to show a message box for us.

The following JScript CA should demonstrate how to do this - it's a bit simple and there's an awful lot more you can do with it but it's a start...

Hope this helps...
Graham

Quote

// Message level
var msiMessageTypeFatalExit = 0x00000000;
var msiMessageTypeError = 0x01000000;
var msiMessageTypeWarning = 0x02000000;
var msiMessageTypeUser = 0x03000000;
var msiMessageTypeInfo = 0x04000000;

// Button styles
var msiMessageTypeOk = 0;
var msiMessageTypeOkCancel = 1;
var msiMessageTypeAbortRetryIgnore = 2;
var msiMessageTypeYesNoCancel = 3;
var msiMessageTypeYesNo = 4;
var msiMessageTypeRetryCancel = 5;

// default button
var msiMessageTypeDefault1 = 0x000;
var msiMessageTypeDefault2 = 0x100;
var msiMessageTypeDefault3 = 0x200;

// return values
var msiMessageStatusError = -1;
var msiMessageStatusNone = 0;
var msiMessageStatusOk = 1;
var msiMessageStatusCancel = 2;
var msiMessageStatusAbort = 3;
var msiMessageStatusRetry = 4;
var msiMessageStatusIgnore = 5;
var msiMessageStatusYes = 6;
var msiMessageStatusNo = 7;

// MessageBox function:
// Parameters:
//   strMessage - the message string to display
//   lngOptions - message box styles, add together a
//     message level, a button style and a default button
// Return value - depends on the button style, for
//     example if msiMessageTypeYesNo is chosen and
//     the user presses the Yes button on the message
//     box then msiMessageStatusYes is returned.
function MessageBox(strMessage, lngOptions)
{
   // use some default message options
   if(lngOptions == null)
   {
       lngOptions = msiMessageTypeUser
           + msiMessageTypeOk
           + msiMessageTypeDefault1;
   }

   var objRecord = Session.Installer.CreateRecord(1);
   objRecord.StringData(0) = "[1]";
   objRecord.StringData(1) = strMessage;

   return Session.Message(lngOptions, objRecord);
}

// Custom action entry point
function CAMsgBox()
{
   var lngMBOpt = msiMessageTypeWarning
       + msiMessageTypeYesNo
       + msiMessageTypeDefault2;
   var lngRet = MessageBox("Yes or no?", lngMBOpt);
   if(lngRet == msiMessageStatusNo)
       MessageBox("You pressed No");
   else
       MessageBox("You pressed Yes");

   return 1;
}



Johannes John

Johannes John
  • Full Members
  • 223 posts

Posted 22 October 2001 - 13:48

Hello Graham,

many, many thanks!
That's great! It's working without problems!
Yes, you'r right, it thought it would be easier, but that doesn't matter now.
This will be the beginning of my great J-Script career.
:-)

Thanks for your effort!
Johannes


miroag

miroag
  • Members
  • 1 posts

Posted 25 October 2001 - 11:46

It could be done a little bit simpler:

var shell = new ActiveXObject("WScript.Shell");
shell.Popup("Hello", 0 , "My Script", 16);



grahamm

grahamm
  • Members
  • 15 posts

Posted 25 October 2001 - 12:26

Fair enough, but that assumes you have Windows 2000, or have installed the WSH. Probably a fair assumption these days...

I'd only noticed the WScript.Echo function before, but you can't create that object from a non-WSH hosted script. Didn't realise there was another message box function hidden away so wrote my own interface to the Installer one.

Cheers
Graham