2

I've created a batch file called restart.bat

:: Open a Telnet window
start telnet.exe 10.20.11.12
:: Run the script
%systemroot%\system32\cscript.exe //Nologo //B C:\Scripts_and_Tools\SendKeys.vbs

This is the vbs script

set OBJECT=WScript.CreateObject("WScript.Shell")
WScript.sleep 50
OBJECT.SendKeys "root{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "password{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "boot action=reset{ENTER}"
WScript.sleep 3000
OBJECT.SendKeys "{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " exit{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " "

Running it manually works fine, but running it as task scheduler it will show it has completed but it didn't work.

lbanz
  • 1,609
  • 5
  • 20
  • 30
  • Are you impersonating a user during the task run? I have a feeling it's failing to run under the SYSTEM account. – Nathan C Jul 14 '14 at 12:07
  • @NathanC I'm running it under a domain admin account. It shows the task is completed but I can see telnet.exe still running in process. – lbanz Jul 14 '14 at 12:45

1 Answers1

2

The task runs in user session 0 by default and does not interact with the desktop. See

windows-7-task-scheduler-to-start-application-in-user-session

You can confirm if this is your issue but running the Task Scheduler task manually while logged into the domain admin account it runs under. The telnet window, etc. should run at that point in the interactive desktop.

For this type of click/keys automation I recommend using Autoit as it can send the input directly to the proper window.

Bin
  • 864
  • 5
  • 15