Vbscript SendKeys在我关闭程序之前不工作

Vbscript SendKeys在我关闭程序之前不工作,vbscript,Vbscript,当我启动计算器模拟器时,它要求输入用户名和密码。我想自动填写这些表格。我的问题是,我的SendKeys在我关闭程序之前不会激活。如果我手动启动程序,我必须先点击tab键,然后才能键入用户名。我不确定我的WshShell.AppActivate是否正常工作或是否需要 Set WshShell = WScript.CreateObject("WScript.Shell") Dim exeName Dim statusCode exeName = "C:\Users

当我启动计算器模拟器时,它要求输入用户名和密码。我想自动填写这些表格。我的问题是,我的
SendKeys
在我关闭程序之前不会激活。如果我手动启动程序,我必须先点击tab键,然后才能键入用户名。我不确定我的
WshShell.AppActivate
是否正常工作或是否需要

Set WshShell = WScript.CreateObject("WScript.Shell")

Dim exeName 
Dim statusCode

exeName = "C:\Users\Administrator\Desktop\AX595-EmulatorV0.7\Emulator.exe"

statusCode = WshShell.Run (exeName, 1, true)

WshShell.AppActivate "Emulator"

WshShell.SendKeys "{TAB}" 
WshShell.SendKeys "myUser" 
WshShell.SendKeys "{TAB}" 
WshShell.SendKeys "myPassword" 
WshShell.SendKeys "{ENTER}"

请尝试执行脚本
Run
,而不是脚本
Exec
。 最简单的设置是:

Set objExec = WshShell.Exec(exeName)
WScript.Sleep 200
WshShell.AppActivate "Emulator"
WScript.Sleep 200

您可能需要调整第一次睡眠延迟时间(取决于您的应用程序启动的时间)

这非常有效。谢谢