none
Task Scheduler not work on vbs RRS feed

  • Question

  • hi create new task for running vbs script

    as below is my script and I try running on CMD is working. but on Task Scheduler is not working!

    set WshShell = WScript.CreateObject("WScript.Shell")
    
    'Open a Telnet connection to router IP'
    'Delay of 4 seconds in between using the Sleep 4000 parameter when entering commands'
    
    WshShell.run"telnet.exe 192.168.5.13"
    WScript.Sleep 4000
    
    'Provide username
    WshShell.SendKeys"root"
    WshShell.SendKeys("{Enter}")
    WScript.Sleep 4000
    
    'Provide user password
    WshShell.SendKeys"xxxxxxxx"
    WshShell.SendKeys("{Enter}")
    WScript.Sleep 4000
    
    'Reboot the router
    WshShell.SendKeys"reboot"
    WshShell.SendKeys("{Enter}")
    as below is setting on Task Scheduler Action. 
    

    on Last Run Result is show (0x41301), is not working it when running on Task Scheduler? 

    how I can run on it? 

    thanks.


    • Edited by chkelvin Tuesday, July 31, 2018 8:53 AM
    Tuesday, July 31, 2018 7:02 AM

Answers

  • You cannot use "SendKeys" under the task scheduler.  It only works in an interactive session.


    \_(ツ)_/

    • Marked as answer by chkelvin Wednesday, August 1, 2018 7:47 AM
    Tuesday, July 31, 2018 9:30 AM

All replies

  • You cannot use "SendKeys" under the task scheduler.  It only works in an interactive session.


    \_(ツ)_/

    • Marked as answer by chkelvin Wednesday, August 1, 2018 7:47 AM
    Tuesday, July 31, 2018 9:30 AM
  • what I should use ? 
    Wednesday, August 1, 2018 1:32 AM
  • There is  nothing that will do what you are trying to do.  You will have to get a telnet COM object that can be run from VBS.  Unfortunately VBS is obsolete and most of these things are gone.


    \_(ツ)_/

    Wednesday, August 1, 2018 1:39 AM
  • is possible I create a .bat and point to the .vbs and on Task Scheduler is set to the .bat file?


    Wednesday, August 1, 2018 4:23 AM
  • That will not change the fact that you are using "SendKeys" which will not work in a scheduled task.

    \_(ツ)_/

    Wednesday, August 1, 2018 6:07 AM
  • ok , thanks for help 
    Wednesday, August 1, 2018 7:47 AM
  • This is possible by deploying the scheduled task as a User GPO Preferences

    "Users Configuration" > "Preferences" > "Scheduled Task" then go "Action" > "New" > "Scheduled Task"

    The update will always make sure the current logged on user (%logondomain\%logonuser%) is the interactive launcher of the task.

    Wednesday, August 1, 2018 8:07 AM
  • This is possible by deploying the scheduled task as a User GPO Preferences

    "Users Configuration" > "Preferences" > "Scheduled Task" then go "Action" > "New" > "Scheduled Task"

    The update will always make sure the current logged on user (%logondomain\%logonuser%) is the interactive launcher of the task.

    "SendKeys" will never run correctly under the task scheduler.  It will be very unreliable.


    \_(ツ)_/

    Wednesday, August 1, 2018 8:10 AM