VBScript-SendKeys的替代方案

VBScript-SendKeys的替代方案,vbscript,sendkeys,Vbscript,Sendkeys,我注意到,当用户未登录或脚本作为本地系统执行时,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.S

我注意到,当用户未登录或脚本作为本地系统执行时,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文件中似乎不起作用…

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

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}"

您可以直接运行该命令。谢谢,但很遗憾这是不可能的,因为我想执行telnet命令。我已经更新了上面的示例,以显示我真正想要做的事情。我认为telnet可以获取脚本文件?Sendkeys是一种非常错误的方法。使用实际上可以编写脚本的
telnet
(例如,从套件中)。切勿将
SendKeys
用于此类自动化。