激活应用程序窗口。
object.AppActivate title
AppActivate 方法返回的布尔值表示过程调用是否成功。该方法将焦点转移到命名应用程序或窗口中,但是并不影响应用程序或窗口是最大化还是最小化。用户执行更改焦点的操作(或关闭窗口)时,焦点移离活动的应用程序窗口。
在确定要激活哪个应用程序时,指定的标题将与正在运行的每个应用程序的标题字符串相比较。如果不存在完全匹配的标题,则将激活标题字符串以 title 开头的所有应用程序。如果还是找不到任何应用程序,则将激活标题字符串以 title 结尾的所有应用程序。如果存在多个名为 title 的应用程序实例,则将随机激活一个实例。
下面的示例演示如何将一个 .wsf 文件用于以不同脚本语言(VBScript 和 Jscript)写成的两个作业。两个作业的功能相同 每个作业都运行 Windows 计算器并将它发送给键击以执行简单的计算。
下面的示例启动 Windows 计算器并使用 AppActivate 来确保计算器在顶部。
<package> <job id="vbs"> <script language="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 </script> </job> <job id="js"> <script language="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); </script> </job> </package>