PowerBasic Museum 2020-A

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Scripting => Windows Script Host => Topic started by: José Roca on July 14, 2008, 07:19:53 AM

Title: IWshShell2.AppActivate Method
Post by: José Roca on July 14, 2008, 07:19:53 AM


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