Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Running telnet in script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,3491
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Running telnet in script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Running telnet in script - 6/22/2005 8:57:17 AM   
  Archimedes

 

Posts: 1
Score: 0
Joined: 6/22/2005
From: USA
Status: offline
Morning,
I'm trying to run telnet through vbs and the way I'm doing it is, I'm sure, ugly.

WshShell.run("telnet server")
oExec = WshShell.AppActivate("telnet")
WScript.Sleep 5000
WshShell.SendKeys "user {enter}"
WScript.Sleep 500
wshShell.SendKeys strPassword & "{enter}"
WScript.Sleep 5000
WshShell.SendKeys "cd stuff {enter}"


Is there a better way to run telnet?

Second, when I enter the last command, it takes serveral hours to complete. How do i get the script to wait until this is done? I've tried several suggestions that I've seen in the forums but, alas, my PC is cursed.
Do
found = False
Set procs = GetObject("winmgmts://./root/cimv2").execquery("select * from win32_process")
For Each proc In procs
If proc.name = "telnet.exe" Then
found = True
End If
Loop

Tells me i have no do before my loop
If I do a .run(telnet,,true) the sendkeys do not go until I close telnet, which is silly.

Any suggesion would be appreciated

Thanks
 
 
Post #: 1
 
 RE: Running telnet in script - 5/3/2006 5:19:36 AM   
  jkgraham

 

Posts: 2
Score: 0
Joined: 5/3/2006
Status: offline
Your code helped me.  I did tweak a few things.  You were missing a NEXT in your FOR NEXT loop.  Below is what I used.  It is also a bit of a hack, but effective.

do until running = "false"
Wscript.sleep(1000)
Set objShell = CreateObject("Wscript.Shell")
objShell.run "ftp.exe",2
set objShell = nothing
checkprocesses
loop

sub checkprocesses()
Set procs = GetObject("winmgmts://./root/cimv2").execquery("select * from win32_process")
found = 0
For Each proc In procs
if proc.name = "ftp.exe" then
  proc.Terminate()
end if
If proc.name = "telnet.exe" Then
  found = found + 1
Else
  found = found + 0
End If
Next
if found = 0 then
running = "false"
else
running = "true"
end if
end sub

It turns out that in order for the telnet.exe to shutdown when it is finished, focus needs to be taken off of the window.  I accomplished this by launching another program then shutting it down.  I used ftp.exe for mine.  I tested notepad.exe, ftp.exe, and notepad.exe.  I found that ftp.exe had the least amount of flickering.  If anyone knows of a better way to do this.  Please let me know.

(in reply to Archimedes)
 
 
Post #: 2
 
 RE: Running telnet in script - 5/3/2006 5:22:30 AM   
  jkgraham

 

Posts: 2
Score: 0
Joined: 5/3/2006
Status: offline
Sorry, the other program that I tested with this code was cmd.exe.  I had notepad in there twice.  Oh, I also tested calc.exe which had the most obvious flickering.

(in reply to jkgraham)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Running telnet in script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts