Skip to content

Instantly share code, notes, and snippets.

@subzey
Created December 25, 2012 17:38
Show Gist options
  • Save subzey/4374329 to your computer and use it in GitHub Desktop.
Save subzey/4374329 to your computer and use it in GitHub Desktop.
Events handling in WSH + JScript example.
// Create a new InternetExplorer.Application object
// 2nd arg is a prefix for events (any string)
var ie = WScript.CreateObject("InternetExplorer.Application", "ieEvent_");
// Set url
ie.Navigate("about:blank");
// Show window (default state is hidden)
ie.Visible = 1;
// Create specially named function using prefix (that 2nd arg above)
// (OnQuit means when IE window is closed)
// This callback must be in global scope!
function ieEvent_OnQuit(){
// Do something useful
WScript.echo('quit');
// Terminate script
WScript.quit();
}
// Infinite idle loop waiting for callback
// (There's no main loop in WSH/JS so there's no sweet setTimeout/setInterval)
while (true){
WScript.sleep(1000);
}
// End of this hell script
@aerze
Copy link

aerze commented Feb 19, 2014

while (true) {
    WScript.echo('Thank you!');
}

@Befzz
Copy link

Befzz commented Dec 7, 2014

Thank u!
Found where it's documented (WSH CreateObject Method Remarks)
( http://msdn.microsoft.com/en-us/library/xzysf6hc(v=vs.84).aspx )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment