Const strCalc = "计算器" '计算器,工具title
'可以循环,也可以不用循环
Do
RunCalc
WScript.Sleep 1000
WScript.quit
Loop
Sub RunCalc()
Dim Wsh,fso
Set Wsh = WScript.CreateObject("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")
WScript.Sleep(1000)
'Wsh.Run "C:\01_工具\工具.exe"
Wsh.Run "calc"
'检查窗口是否出现
Do While Wsh.AppActivate(strCalc) = False
WScript.sleep 1000
'MsgBox "启动成功"
Loop
'激活窗口
Call WindowActive(strCalc)
WScript.sleep 1000
Wsh.sendkeys "123456789"
'下面两个命令分别用来点击tab键和回车键
'Wsh.sendkeys "{tab}"
'Wsh.sendkeys "{enter}"
Set Wsh=NoThing
End Sub
'激活窗口
Sub WindowActive(ByVal strWindowTitle)
Dim objWord, objTasks
Set objWord = CreateObject("word.Application")
Set objTasks = objWord.Tasks
If objTasks.Exists(strWindowTitle) Then
objTasks(strWindowTitle).Activate '激活此窗口
objTasks(strWindowTitle).WindowState = 0 '0:normal、1:最大化、2:最小化
End If
objWord.Quit
End Sub