Hi all,

I am trying to get a batch / vbs script to auto-logon to a telnet
server. Basically the batch file below creates and runs a vbs script on
the fly. I actually got the idea from another Google posting. The
problem is the SendKeys are not being sent to the telnet window. I have
changed the target to notepad and I am left with an empty screen. Can
any one suggest a way of getting this working?

Many thanks for your time.

Paul


@echo off
echo set sh=WScript.CreateObject("WScript.Shell")>telnet.vbs
echo WScript.Sleep 500>>telnet.vbs
echo sh.SendKeys "my_password">>telnet.vbs

start /realtime telnet 192.168.0.1
C:\WINNT\system32\cscript.exe //nologo telnet.vbs

Re: Auto-logon to a telnet server by toolman

toolman
Mon Dec 05 10:37:01 CST 2005

I use this code and it works well:

'VBScript to Send An E-mail via Telnet - generally as an alert to some
opertional problem
'Written by and the intellectual property of John Gammel
(www.gammel.com)
'Tested with a broadband connection to comcast.net
'Tested with WindowsXP Professional/SP2 and the keystrokes are visible
'Tested with Windows2000 Professional - less keystrokes visible but
still works
' runs correctly both standalone and as a scheduled task
'
'chr(34) is the double tick (") and is to get around not being able to
use it directly in a string
'tilde (~) is used to perform the "enter" key
'option explicit is used to reduce the likelihood that typographical
errors go unnoticed
'
'The calling routine has been deliberately kept simple - it just checks
local "C" drive free space
'To keep the script simple it does not look at the output of the server
- hence the sleep parameters
'The SendEMail group of string variables need to be changed to meet
local requirements
'The WScript.Sleep amounts might need adjustment to better match the
speed of the smtp server
'When adapting this to an environment I recommend that you actually
type each command in a cmd window
' so that you can see what the destination system returns and how
quickly since you will likely have
' to make adjustments to the code such as adding a userid and
password, etc.

'Main calling routine
option explicit
const vMinFreeSpaceC = "999999999"
dim objWMIService, objLogicalDisk, vFreeSpace
Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk =
objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
vFreeSpace = objLogicalDisk.FreeSpace
If vFreeSpace < "999999999" Then
SendEMail (vFreeSpace)
End If

Sub SendEMail (sFreeSpace)
dim sdomain, ssmptserver, sport, smailacctfr, smailacctto, smailnamefr,
smailnameto
dim sopen, ssubject, sehlo, smailfr1, smailto1, smailfr2, smailto2,
WSHShell
sdomain = "comcast.net"
ssmptserver = "smtp.comcast.net"
sport = "25"
smailacctfr = "<someid1234567890@yahoo.com>"
smailacctto = "<someid0987654321.com>"
smailnamefr = "somename12"
smailnameto = "somename09"

sFreeSpace = sFreeSpace & "~"

sopen = "open " & ssmptserver & " " & sport & "~"
ssubject = "Subject: Telnet Test with VBScript at " & Now() & "~"
sehlo = "EHLO " & sdomain & "~"
smailfr1 = "MAIL FROM: " & smailacctfr & "~"
smailto1 = "RCPT TO: " & smailacctto &"~"
smailfr2 = "FROM: " & chr(34) & smailnamefr & chr(34) & smailacctfr &
"~"
smailto2 = "TO: " & chr(34) & smailnameto & chr(34) & smailacctto & "~"

Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run "Telnet"
WSHShell.AppActivate "Telnet"
WScript.Sleep 2000
WSHShell.SendKeys sopen
WScript.Sleep 5000
WSHShell.SendKeys sehlo
WScript.Sleep 2000
WSHShell.SendKeys smailfr1
WScript.Sleep 2000
WSHShell.SendKeys smailto1
WScript.Sleep 2000
WSHShell.SendKeys "DATA~"
WScript.Sleep 2000
WSHShell.SendKeys smailfr2
WScript.Sleep 500
WSHShell.SendKeys smailto2
WScript.Sleep 500
WSHShell.SendKeys ssubject
WScript.Sleep 500
WSHShell.SendKeys "~"
WScript.Sleep 500
WSHShell.SendKeys "Below Disk Space Threshold~"
WScript.Sleep 500
WSHShell.SendKeys sFreeSpace
WScript.Sleep 500
WSHShell.SendKeys "Immediate Action Required~"
WScript.Sleep 500
WSHShell.SendKeys ".~"
WScript.Sleep 5000
WSHShell.SendKeys "quit~"
WScript.Sleep 5000
WSHShell.SendKeys " ~"
WScript.Sleep 5000
WSHShell.SendKeys "quit~"
WScript.Sleep 5000
End Sub