title: Restarting Webservice running in a CMD-window with a simple script
body: <p>I have a webservice running in a cmd window on a server.
  I have no access to directly interfer with it, other than going into the window and stopping in manually (with ctrl+c) and starting it again.</p>
  
  <p>The task was to restart it at certain times. So to properly close I select the window, maximize it, send ctrl+c, wait until the confirmation pops up and confirm with "J" (this is not wrong, it's a german client) and ENTER.
  Then Wait a bit and start it with the provided bat again.</p>
  
  <p>Here's the script:</p>
  
  <pre><code>Set shell = CreateObject("WScript.Shell")
  
  shell.AppActivate "Administrator:  WebGui"
  
  wscript.Sleep 5000
  shell.SendKeys "% x"
  wscript.Sleep 1000
  shell.SendKeys "^C"
  wscript.Sleep 60000
  shell.SendKeys "J"
  wscript.Sleep 1000
  shell.SendKeys "{ENTER}"
  wscript.Sleep 10000
  
  shell.CurrentDirectory = "C:\webapps\web_gui"
  shell.Run "runWebGui.bat"
  
  wscript.Sleep 10000
  shell.SendKeys "% n"
  </code></pre>
  
  <p>Manually everything works, but the moment I use the Task-Schedular or a script to let it be done automatically, it doesn't seem to work.</p>
  
  <p>Here the script I tried to use in place of the Task-Schedular.</p>
  
  <pre><code> 'timer.vbs
   Set objShell = Wscript.CreateObject("Wscript.Shell")
  
   Do
        Wscript.Sleep 1000
        If Time() = TimeValue("6:45:00 AM") Then 
             objShell.Run "c:\windows\system32\cscript.exe /B /nologo C:\login\g-restart.vbs"
             Wscript.echo "Neustart um 6:45 gestartet"
        ElseIf Time() = TimeValue("12:00:00 PM") Then 
             objShell.Run "c:\windows\system32\cscript.exe /B /nologo C:\login\g-restart.vbs"
             Wscript.echo "Neustart um 12:00 gestartet"
        ElseIf Time() = TimeValue("5:00:00 PM") Then 
             objShell.Run "c:\windows\system32\cscript.exe /B /nologo C:\login\g-restart.vbs"
             Wscript.echo "Neustart um 17:00 gestartet"
        End If
   Loop
  </code></pre>
  
  <p>I both cases it seems like the issue lies with AppActivate and then sending keys, when it's not done manually. Since the key-presses aren't sent towards the active window, but towards whatever is in the foreground...</p>
  
  <p>So I assume the issue lies somewhere in here:</p>
  
  <pre><code>shell.AppActivate "Administrator:  WebGui"
  
  wscript.Sleep 5000
  shell.SendKeys "% x"
  wscript.Sleep 1000
  shell.SendKeys "^C"
  wscript.Sleep 60000
  shell.SendKeys "J"
  wscript.Sleep 1000
  shell.SendKeys "{ENTER}"
  </code></pre>
  
  <p>Is there any easy solution to my problem?</p>