Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

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

Reply
 
Old 07-31-2009   #1 (permalink)
tctatum


 
 

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

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"% "
_________________________

My System SpecsSystem Spec
Old 07-31-2009   #2 (permalink)
tctatum


 
 

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

The problem lines are:
Quote:

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

> 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.
My System SpecsSystem Spec
Old 07-31-2009   #3 (permalink)
Pegasus [MVP]


 
 

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


"tctatum" <tc_tatum@xxxxxx> wrote in message
news:EAB0AFA7-6790-4C9B-BAD5-224422D61BE3@xxxxxx
Quote:

>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"% "
> _________________________
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/micro...9c7776bdb5bb24


My System SpecsSystem Spec
Old 08-01-2009   #4 (permalink)
Al Dunbar


 
 

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


"Pegasus [MVP]" <news@xxxxxx> wrote in message
news:ugIMBvfEKHA.5780@xxxxxx
Quote:

>
> "tctatum" <tc_tatum@xxxxxx> wrote in message
> news:EAB0AFA7-6790-4C9B-BAD5-224422D61BE3@xxxxxx
Quote:

>>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"% "
>> _________________________
>
> 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/micro...9c7776bdb5bb24
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:
Quote:
Quote:

>> oShell.SendKeys("[%user%]")
to:
Quote:
Quote:

>> oShell.SendKeys(user)

/Al


My System SpecsSystem Spec
Old 08-03-2009   #5 (permalink)
HCartan


 
 

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

On Jul 31, 1:13*pm, tctatum <tc_ta...@xxxxxx> wrote:
Quote:

> 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 outthe
> 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)? *Thebold
> 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"% "
> _________________________
Hi,

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



My System SpecsSystem Spec
Old 08-04-2009   #6 (permalink)
Reventlov


 
 

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

Il giorno Mon, 3 Aug 2009 06:12:01 -0700 (PDT), HCartan <henrytejera@xxxxxx> ha
scritto:
Quote:

>On Jul 31, 1:13=A0pm, tctatum <tc_ta...@xxxxxx> wrote:
Quote:

>> 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)
--
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Pop-up to enter variables to pass to script PowerShell
how do you pass named params to funcs by way of variables PowerShell
server asking VISTA for user name and password Vista security
server asking VISTA for user name and password Vista networking & sharing
server asking VISTA for user name and password Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46