VBScript - SendKeys的替代方案

时间:2013-09-18 13:36:06

标签: vbscript sendkeys

我注意到当用户未登录或脚本作为LOCAL SYSTEM执行时,VBScript中的SendKeys不起作用。

示例:

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "telnet 192.168.1.50"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "some telnet command"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "another telnet command"
WshShell.SendKeys "{ENTER}"

还有其他方法可以将密钥发送到应用程序吗? SendInput似乎不能在.vbs文件中运行...

1 个答案:

答案 0 :(得分:2)

根据你的限制,我会这样做:

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd"
WScript.Sleep 100 
WshShell.AppActivate "C:\Windows\system32\cmd.exe" 
WScript.Sleep 100 
WshShell.SendKeys "telnet 192.168.1.50"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "some telnet command"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "another telnet command"
WshShell.SendKeys "{ENTER}"