0

Below is the Current Script I have for my current little project.

<job>
    <script language="VBScript">
    Option Explicit
    On Error Resume Next
    Dim WshShell
    set WshShell=CreateObject("WScript.Shell")
    WshShell.run "cmd.exe", 2
    WScript.Sleep 50
    'Send commands to the window as needed - IP and commands need to be customized
    'Step 1 - Telnet to remote IP'
    WshShell.SendKeys "telnet 192.168.0.1 23"
    WshShell.SendKeys ("{Enter}")
    WScript.Sleep 50
    WshShell.SendKeys ("root{Enter}")
    WScript.Sleep 50
    WshShell.SendKeys ("foo{Enter}")
    WScript.Sleep 50
    WshShell.SendKeys ("cd /work/Tools{Enter}")
    WScript.Sleep 50
    WshShell.SendKeys ("control_videosignal.sh -fbas 1{Enter}")
    WScript.Sleep 50 
    WshShell.SendKeys "exit{ENTER}" 'close telnet session' 
    WshShell.SendKeys "{ENTER}" 'get command prompt back 
    WScript.Sleep 50 
    WshShell.SendKeys "exit{ENTER}" 'close cmd.exe
    WshShell.SendKeys "{ENTER}" 'get command prompt back 
    WScript.Sleep 1000
    WshShell.SendKeys "{ENTER}" 'get command prompt back 
    WScript.Sleep 200 
    WshShell.SendKeys "exit{ENTER}" 'close cmd.exe
    </script>
    </job

The result is it stops at this point.

Stops here

I just want the current cmd.exe window to close when the script exits.

Any help is appreciated.

WshShell.SendKeys ("control_videosignal.sh -fbas 1{Enter}")
WScript.Sleep 50
WshShell.SendKeys ("{Enter}")
WScript.Sleep 200
WshShell.SendKeys "^{C}"
WScript.Sleep 200
WshShell.SendKeys ("exit{Enter}")
WScript.Sleep 3000
WScript.Quit
</script>
</job>

Connection Just closes without Executing.

1 Answers1

1

It looks like you're stuck in Telnet, which uses the command quit rather than exit I believe.

Try using:

WshShell.SendKeys "quit{ENTER}"

or

WshShell.SendKeys "^{C}"

To make sure you've properly quit Telnet, before issuing exit to cmd.

Jonno
  • 21,643