none
How to run a VBscript function in an instance of IE?

    Question

  • From my (VB)script I create an IE object and have it load a webpage. This HTML page also contains a script tag with some VBscript procedures.

    Now how can I run one of these procedures and hand over parameters from within my originial script?

    I tried  objIE.Document.InvokeScript("TestProc")  but I get the error that this method does not exist (which is only fair as I realized this method is defined in the .NET realm).

    Any way to achieve this in VBscript?


    • Edited by wmelonman Friday, February 08, 2013 1:40 AM
    Friday, February 08, 2013 1:13 AM

Answers

  • An HTA is a DHTML document that runs exactly like a local application. That is, it can use all ActiveX objects on the machine, not just the ones that are marked as "safe for scripting." For example, an HTA can use FileSystemObject to access the local file system. HTAs get executed by mshta.exe instead of a browser application.

    There aren't any special development tools needed to create an HTA - just rename your DHTML document using the .hta extension and run it.

    Introduction to HTML Applications (HTAs)

    Bill

    Friday, February 08, 2013 6:24 PM
    Moderator

All replies

  • Hi,

    If I understand your question, the answer is no. But the larger question is why do you need to?

    Bill

    Friday, February 08, 2013 3:40 PM
    Moderator
  • @Bill: Hi Bill,

    thanks for your answer. The HTML page is multipurpose GUI that I use together with different VBS scripts. The GUI takes parameters that are read from the scripts as well as it shows logging output from the scripts and controls start/stop for the main action inside the script.

    What I want now is that the GUI automatically runs an init function on startup wherein it does things influenced by which script it has been created from and take arguments like which INI file to load.

    Today I've come across the SetTimeout() method of the browser's window object. So for the moment I plan on using either a registry key or hidden form controls inside the GUI to provide the arguments given from the scripts. Then the GUI would start the init procedure itself by means of SetTimeout() with a delay of 500ms.

    Still it would be more elegant to have a way the script could trigger some action in the GUI. FireEvent() would be nice but it seems to me these methods are not available in vbscript either.

    Maybe there is some cool way I did not think of?

    Martin

    Friday, February 08, 2013 5:16 PM
  • It sounds to me like an HTA would be more useful in your scenario.

    Bill

    Friday, February 08, 2013 5:22 PM
    Moderator
  • I never really looked into HTAs. Could you please briefly give me an idea what the benefits would be? Or some keywords for me to look up concerning mechanisms a HTA provides that would cover my needs?

    Martin

    Friday, February 08, 2013 6:18 PM
  • An HTA is a DHTML document that runs exactly like a local application. That is, it can use all ActiveX objects on the machine, not just the ones that are marked as "safe for scripting." For example, an HTA can use FileSystemObject to access the local file system. HTAs get executed by mshta.exe instead of a browser application.

    There aren't any special development tools needed to create an HTA - just rename your DHTML document using the .hta extension and run it.

    Introduction to HTML Applications (HTAs)

    Bill

    Friday, February 08, 2013 6:24 PM
    Moderator
  • So I'll take a little HTA dive and see where it leads me... always good to learn sth new :-)

    Thanks for your time and for the link, seems like a good starting point and has some interesting comments.

    Martin

    Friday, February 08, 2013 11:03 PM