Help my rubbish VBScript

Soldato
Joined
27 Aug 2004
Posts
2,955
Location
Singapore ExPat
Have tried knocking this little script up this morning, it kinda works except you can't cancel out of it if you want to...what am I missing? Something in the Loop or the If statement is ruining it I think...

Code:
'Simple script to open a telnet session with a chosen server

Option Explicit
Dim objShell, intCount, strServer, strInput


' Input Box to get name of server to connect to
'Do 
strServer = (InputBox(" Server to connect to:", "CRT Replacement"))
     If strServer <> "" Then
     strInput = True
     End if
'Loop until strInput = True

'Open command prompt

Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd" 
WScript.Sleep 1000
objShell.AppActivate "C:\windows\system32\cmd.exe"

'send relevant commands to window.

objShell.SendKeys "telnet" 
objShell.SendKeys "{ENTER}" 
objShell.SendKeys "o " 
objShell.SendKeys strServer
objShell.SendKeys "{ENTER}"
 
It's pieced together from other scripts, I left it in just in case I might need it later, is that causing the problem?
 
Yep exactly, it just telnets onto a server, it works fine except if you press cancel it just keeps looping. What I want is if you press Cancel for it to just exit out of the script entirely, if I remove the loop and press cancel it cancels the input box but the rest of the script continues. Sorry, as you can see I am not very good at scripting...
 
Back
Top Bottom