![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | RE: VBS Telnet to Server and Pass Variables for User and Password?? The problem lines are: Quote: > oShell.SendKeys("[%user%]") Quote: > oShell.SendKeys("[%pass%]") possible. If so, not sure of context. Tried several combinations, but no luck. Thanks for anyone's input. |
My System Specs![]() |
| | #3 (permalink) |
| | 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"% " > _________________________ 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 Specs![]() |
| | #4 (permalink) |
| | 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 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%]") Quote: Quote: >> oShell.SendKeys(user) /Al |
My System Specs![]() |
| | #5 (permalink) |
| | 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"% " > _________________________ For this task it is best to use AUOTIT (http://www.autoitscript.com/ autoit3/) |
My System Specs![]() |
| | #6 (permalink) |
| | 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" 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 Specs![]() |
![]() |
| 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 | |||