1

I'm trying to figure out how I can add a JScript event handler to a COM interface. In this API

http://helpnet.installshield.com/installshield17helplib/IHelpAutoISWiRelease.htm

there are 3 Build Status Events I want to observe. Reading Microsofts documentation

http://msdn.microsoft.com/en-us/library/vstudio/06t47502(v=vs.100).aspx

leads me to believe I need to use a ISWiRelease.add_XXXXX(event_function) approach. But the ISWiRelease documentation does not list the "add event handler" methods.

Figuring this out seems like it should be simple. But I'm banging my head against a wall. There is an example for detecting the events with Visual Basic here

http://helpnet.flexerasoftware.com/installshield21helplib/helplibrary/AutomationBuildStatEv.htm

but that is of little help to me.

I tried to list the functions/methods using these approaches

How to display all methods of an object in Javascript?

How to list the functions/methods of a javascript object? (Is it even possible?)

but when I loop over the ISWiRelease object it acts as if it is empty.

How can I figure out the names of the addXXXX(..) event functions?

Additional Info:

  • I'm a JScript/wsf noob
  • The JScript is called via a .wsf file and cscript
  • I tried to add a basic import System; to the .js file which gave a syntax error (not sure why)
  • I'm only lightly scratching this project. I did not set it up, choose to use cscript or the Automation Interface, and would be much happier with calling the command line tool instead but I'm not in a position to make that sizeable a change.
  • This is a follow up to Redirecting the InstallShield log to console
Community
  • 1
  • 1
Shane Gannon
  • 6,770
  • 7
  • 41
  • 64

1 Answers1

1

Is your JScript code inside the WSF file? If so, you can add an <object> reference with events="true". Then you can define event handler functions using the objectName::eventName syntax. For example:

<job>
  <object id="oWord" progid="Word.Application" events="true"/>
  <script language="JScript">
    function oWord::NewDocument(oDoc) {
      WScript.Echo("New document: " + oDoc.Name);
    }

    oWord.Visible = true;
    oWord.Documents.Add(); // fires the event handler
    oWord.Documents.Add(); // fires the event handler again
    WScript.Sleep(2000);
    oWord.Quit();
  </script>
</job>

(The MSDN article you linked to is about JScript.NET, which is separate from Windows Script Host.)

Helen
  • 87,344
  • 17
  • 243
  • 314