Piggymoo - A forum lost in time and space

Did you know we have 4112 anime wallpapers?
VB scripting - close telnet window?

 
Post new topic   Reply to topic    Piggymoo.com Forum Index -> webdesign
View previous topic :: View next topic  
Author
Message
Spanner_
Ascended piggy
Ascended piggy


Joined: Sun Jan 06, 12008 3:29 pm
Posts: 2300


Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7
Add reputation for this poster

PostPosted: Tue Mar 10, 12009 9:25 pm    Post subject: VB scripting - close telnet window? Reply with quote


Dunno if any of you guys will have experience with VB but thought I'd give you a shot Razz

Basically I've grabbed bits of code off the web and edited slightly to create a vb script which, in essence, opens up the command prompt, uses windows' telnet command to connect to my local router, enters the user name and password and restarts the router.

Everything works fine (!) except that I cannot find any way to close the telnet connection window. - it is left in a state where any inputs go straight to the router, not the telnet command, and since the system is restareting, there are no commands available.

I have tried using send keys to send alt-f4 and alt-space c keypresses to close the command prompt window but this does not work.

Anyway, here's what I got:

Code:
Set oShell = WScript.CreateObject ("WScript.shell")
oShell.run "telnet 192.168.1.1"
CreateObject("WScript.Shell").AppActivate "Telnet 192.168.1.1"

Set WSHShell = WScript.CreateObject("WScript.shell")
Wscript.Sleep 1*500
WSHShell.SendKeys "username~"
Wscript.Sleep 1*500
WSHShell.SendKeys "password~"
Wscript.Sleep 1*500
WSHShell.SendKeys "system restart~"

Wscript.Sleep 2*1000
{CLOSE WINDOW COMMAND HERE}


Any assistance would be most appreciated.
Very Happy
Back to top
View user's profile Send private message
Spanner_
Ascended piggy
Ascended piggy


Joined: Sun Jan 06, 12008 3:29 pm
Posts: 2300


Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7
Add reputation for this poster

PostPosted: Tue Mar 10, 12009 10:02 pm    Post subject: Reply with quote


Found a solution!

Code:
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}")
Set objProcess = objWMI.InstancesOf("Win32_process")
For each Process in objProcess
If (instr(1,lcase(Process.name),lcase("telnet.exe")) > 0) then
Process.terminate 0
End If
Next


Just incase anyone else happens accross this.
Back to top
View user's profile Send private message
sabados
AKA Chairman Meow
AKA Chairman Meow


Joined: Sun Aug 17, 12008 11:05 pm
Posts: 1211
Location: In the vast unknown regions of the universe where space and time become one

Reputation: 141.1Reputation: 141.1Reputation: 141.1Reputation: 141.1Reputation: 141.1Reputation: 141.1Reputation: 141.1
Add reputation for this poster

PostPosted: Tue Mar 10, 12009 10:21 pm    Post subject: Reply with quote


uh... what has this got to do with web design?


also, you could just use a bat, alot easier and no SHITB required.
Back to top
View user's profile Send private message AIM Address MSN Messenger
Spanner_
Ascended piggy
Ascended piggy


Joined: Sun Jan 06, 12008 3:29 pm
Posts: 2300


Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7Reputation: 216.7
Add reputation for this poster

PostPosted: Tue Mar 10, 12009 10:32 pm    Post subject: Reply with quote


Nothing really but if you code shit then you probably used vb at one point or another. Not to mention vb seems to be used quite a bit for server and client side web applications.

Anywho, you can't just use a bat cus:

1) Once telnet is executed it is it's own program thus a bat cannot communicate with it.
2) batch files (so far as i know) can't input parameters into the telnet program beyond the arguments that can be entered as per telnet.exe "telnet.exe -l -a -f etc."

Since telnet is designed to simply forward communications to another device, there are no arguments for "username / password" or "commands to execute on the router" since the router's commands will vary from make to make.

When I started looking into this (to get jDownloader to reset my router) I did try using bats but had no success beyond opening the telnet connection.

Then I progressed to a bat that opened telnet in a seperate window followed by a set of vbscripts that inputted key presses. Obv this spanned a few files so I thought I'd combine them in one vbscript given that running telnet is not complicated.
Back to top
View user's profile Send private message
passerby
baby piggy
baby piggy


Joined: Wed Mar 07, 12012 5:22 am
Posts: 1



Add reputation for this poster

PostPosted: Wed Mar 07, 12012 5:31 am    Post subject: Reply with quote


Forgive me for bumping an old thread but this result is on google and it may help someone else.
I used the above method to close telnet and it worked but it required me to make an external vbs
because I was using it in an html page, no getObject access from within the html.

I did manage a more suitable work-around, I don't know why I didn't think of it sooner but that's how coding
with a terrible language is, confuses your instincts.

Here is what I used:
Code:

'This is the standard telnet escape. Ctrl+]
'It will back you out of an active telnet session I was on as400
SendKeys "^]"
Sleep 500
'Quit the telnet program
SendKeys "quit{ENTER}"
Sleep 500
'Quit command prompt
SendKeys "exit{ENTER}"


My code is not whole, my code has a sub for Sleep and SendKeys but anyone looking should get the idea.
Back to top
View user's profile Send private message
Display replies from:   
Post new topic   Reply to topic    Piggymoo.com Forum Index -> webdesign All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2011 phpBB Group
Flower Power phpBB theme by Flowers Online. modified by piggymoo
DMCA, C&D, Legal, privacy