• Welcome to Jose's Read Only Forum 2023.
 

IWshShell2.AppActivate Method

Started by José Roca, July 14, 2008, 07:19:53 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example starts the Windows calculator and uses AppActivate to ensure that the calculator is at the top.

JScript


var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.Run("calc");
WScript.Sleep(100);
WshShell.AppActivate("Calculator");
WScript.Sleep(100);
WshShell.SendKeys("1{+}");
WScript.Sleep(500);
WshShell.SendKeys("2");
WScript.Sleep(500);
WshShell.SendKeys("~");
WScript.Sleep(500);
WshShell.SendKeys("*3");
WScript.Sleep(500);
WshShell.SendKeys("~");
WScript.Sleep(2500);


VBScript


set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc"
WScript.Sleep 100
WshShell.AppActivate "Calculator"
WScript.Sleep 100
WshShell.SendKeys "1{+}"
WScript.Sleep 500
WshShell.SendKeys "2"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "*3"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 2500


PowerBASIC


DIM pWsh3 AS IWshShell3
DIM lExitCode AS LONG
DIM vApp AS VARIANT
pWsh3 = NEWCOM "WScript.Shell"
lExitCode = pWsh3.Run(UCODE$("calc"))
SLEEP 100
vApp = "Calculator"
pWsh3.AppActivate vAppSLEEP 100
pWsh3.SendKeys UCODE$("1{+}")
SLEEP 500
pWsh3.SendKeys UCODE$("2")
SLEEP 500
pWsh3.SendKeys UCODE$("~")
SLEEP 500
pWsh3.SendKeys UCODE$("*3")
SLEEP 500
pWsh3.SendKeys UCODE$("~")
SLEEP 2500