Pergunta

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...

Foi útil?

Solução

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}"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top