Reputation: 729
I have noticed that SendKeys inside a VBScript does not work when the user is not logged in or the script is being executed as LOCAL SYSTEM.
Example:
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}"
Is there any other way to send keys to an application? SendInput does not seem to work in a .vbs file...
Upvotes: 0
Views: 17834
Reputation: 555
Based on your constraints, this is what I would do:
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}"
Upvotes: 2