Windows Server TechCenter > Windows Server Forums > Management > Scheduled VBS sendkeys task does not complete when not logged on, WS03
Ask a questionAsk a question
 

Proposed AnswerScheduled VBS sendkeys task does not complete when not logged on, WS03

  • Thursday, October 29, 2009 1:17 PMJamie A Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello
    I have a scheduled task on WS03.  It is a VBScript file that edits a text file, then restarts tomcat using a command window.

    My (novice) code to restart the service is

    Dim objShell, intShortSleep, intLongSleep Dim strService Set objShell = CreateObject("WScript.Shell") ' Values set strService = " tomcat5" intShortSleep = 500 intLongSleep = 3000 ' Cmd prompt opened objShell.Run "cmd" WScript.Sleep intShortSleep ' Service stopped objShell.SendKeys "net stop" & strService WScript.Sleep intShortSleep objShell.SendKeys "{Enter}" WScript.Sleep intLongSleep ' service restarted objShell.SendKeys "net start" & strService WScript.Sleep intShortSleep objShell.SendKeys "{Enter}" WScript.Sleep intLongSleep ' Cmd prompt exited objShell.SendKeys "Exit" Wscript.Sleep intShortSleep objShell.SendKeys "{Enter}"
    When executed manually, it all works fine.
    When scheduled, the job reports success (0x0), the text file is edited, but tomcat is not restarted, and the command window is left open when I log into the server.  It seems all of the objShell.SendKeys comands are blocked from executing while no one is logged in, is this expected behaviour?
    Any help would be much appreciated

All Replies

  • Sunday, November 01, 2009 3:31 PMGunner999 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer

    Just use a batch file to start and stop the service....don't use VBScript to open a command prompt and run the same commands you can run from a batch file just as easily....this is sort of a Rube Goldberg approach.

    Not sure what you mean by the "text file is edit" i don't see any code to edit files.

    Simple batch file...don't even need the pauses.

    Net stop tomcat5

    Net start tomcat5

     

     

    • Proposed As Answer byGunner999 Friday, November 06, 2009 3:30 AM
    •