EmEditor Home - EmEditor Help - EmEditor Macro Reference - Tutorial

Run External Applications

To run an external application, use the Run Method of WshShell Object.

The following example code runs the Windows calculator and sends it keystrokes to execute a simple calculation 1+2=.

[JavaScript]

WshShell = new ActiveXObject( "WScript.Shell" );
WshShell.Run( "calc.exe" );
Sleep( 1000 );
wnd = shell.FindWindow( "", "Calculator" );
wnd.SetForeground();
shell.SendKeys( "1" );
Sleep( 100 );
shell.SendKeys( "{+}" );
Sleep( 100 );
shell.SendKeys( "2" );
Sleep( 100 );
shell.SendKeys( "=" );

[VBScript]

Set WshShell = CreateObject( "WScript.Shell" )
WshShell.Run "calc.exe"
Sleep 1000
wnd = shell.FindWindow( "", "Calculator" )
wnd.SetForeground
shell.SendKeys "1"
Sleep 100
shell.SendKeys "{+}"
Sleep 100
shell.SendKeys "2"
Sleep 100
shell.SendKeys "="

References

Microsoft MSDN Library: Run Method

Copyright 2003-2015 by Emurasoft, Inc.