Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBS Telnet to Server and Pass Variables for User and Password??

367 views
Skip to first unread message

tctatum

unread,
Jul 31, 2009, 12:13:01 PM7/31/09
to

I am trying to write a script that will allow me to Telnet to a Server and
pass a few commands to start a backup, so far I have gotten as far as logging
into the server via telnet and trying to pass the captured variables ("user"
and "pass") noted below at the beginning of the code. If I comment out the
prompts and hardcode the username and password in the code it works file. I
would like to prompt for the user and password.. Is this possible to call
stored variables using the sendkeys command (I know my syntax is incorrect
for calling the variables, please correct if you know a solution)? The bold
sections below contain the incorrect syntax for calling the variables, this
is where I am not finding a solution. Is there an easy way to do this with a
VBS?

Once this part is resolved I will add the rest of the code which sends
additional commands, which is not a problem.
_____________________________
'Get Username and Password
user = inputbox("Please Enter Username")
pass = inputbox("Please Enter Password")
'Create the shell object
Set oShell = CreateObject("WScript.Shell")
'Start up command prompt
oShell.run"cmd.exe"
WScript.Sleep 500
'Send keys to active window
oShell.SendKeys"telnet xxx.xxx.xxx.xxx"
'Emulate the enter key
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
'write the username to the cmd window
oShell.SendKeys("[%user%]")
oShell.SendKeys("{Enter}")
WScript.Sleep 500
'write the password to the cmd window
oShell.SendKeys("[%pass%]")
oShell.SendKeys("{Enter}")
WScript.Sleep 500
oShell.SendKeys"ls"
oShell.SendKeys("{Enter}")
WScript.Sleep 500
'Exit the program
oShell.SendKeys"% "
_________________________

tctatum

unread,
Jul 31, 2009, 12:21:01 PM7/31/09
to
The problem lines are:

> oShell.SendKeys("[%user%]")

> oShell.SendKeys("[%pass%]")

Not sure if calling a variable in using the SendKeys shell command is
possible. If so, not sure of context. Tried several combinations, but no
luck. Thanks for anyone's input.

Pegasus [MVP]

unread,
Jul 31, 2009, 12:26:58 PM7/31/09
to

"tctatum" <tc_t...@ncports.com> wrote in message
news:EAB0AFA7-6790-4C9B...@microsoft.com...

Your script is completely dependent on macros. Unfortunately macro programs
are notorious for failing for all sorts of reasons. If you want something
robust and stable then you must avoid them. Have a look at this thread about
a method that avoids macros. Post again if you need more help with
implementing your particular project.
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_thread/thread/529c7776bdb5bb24


Al Dunbar

unread,
Aug 1, 2009, 7:14:32 PM8/1/09
to

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message
news:ugIMBvfE...@TK2MSFTNGP03.phx.gbl...

That said, it looks like he is assuming that environment variables and
vbscript variables are one and the same. I agree that sendkeys is a method
of last resort, but he could try changing, for example:

>> oShell.SendKeys("[%user%]")

to:

>> oShell.SendKeys(user)


/Al

HCartan

unread,
Aug 3, 2009, 9:12:01 AM8/3/09
to

Hi,

For this task it is best to use AUOTIT (http://www.autoitscript.com/
autoit3/)

Reventlov

unread,
Aug 4, 2009, 3:20:37 PM8/4/09
to
Il giorno Mon, 3 Aug 2009 06:12:01 -0700 (PDT), HCartan <henry...@gmail.com> ha
scritto:

>On Jul 31, 1:13=A0pm, tctatum <tc_ta...@ncports.com> wrote:
>> I am trying to write a script that will allow me to Telnet to a Server and
>> pass a few commands to start a backup, so far I have gotten as far as logging
>> into the server via telnet and trying to pass the captured variables ("user"
>For this task it is best to use AUTOIT (http://www.autoitscript.com/autoit3/)

Yes, AutoIt is far more reliable in sending keys to a window than sendkeys.
With Autoit you can wait until a certain window comes up and do not risk to send
keystrokes to something else if the user switches to another window.

I tried a small program called NetCat which allows to open a connection and send data from
a text file.

wshShell.run "%comspec% /C nc.exe " & server & " 110 <command.txt >output.txt",7,true

--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--

0 new messages