Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing form values to whshell.SendKeys

Status
Not open for further replies.

asorensen

Technical User
Mar 16, 2002
2
US
I am trying to have users submit values (login and password in the example below) via a form, and have those values passed through to the wshshell.SendKeys command to be sent to a remote host via a telnet session.

I can have values sent using wshshell.SendKeys if I specify them in quotes in the actual code and the program will work just fine, however I would like to be able to use the values entered in the form rather than manually reconfigure the script for each user.

I think the main problem I am having is that I simply do not know they proper syntax for implementing this idea. I have noted places in the code that are obviously wrong with '<-??? What code should I use in those places?

Is there an easier way to do this same type of thing using a different method? I would like to get this to work in vbscript and in vb so comments on both are welcome as well as any other useful info.

This is my first vbscript ever and I do not know much of the proper syntax, so there may be a very simple solution to this problem. Again, please feel free to suggest alternate methods for achieving the same result.

Thank you,
Andrew

A trimmed down yet relatively workable version of the full code and it's html wrapper are listed below:


<HTML>
<HEAD>
<TITLE>Telnet User Authentication</TITLE>

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
<!--

Sub cmdConfigure_OnClick

' Check to see if the user entered a login.
If (Len(document.loginpass.txtLogin.value) = 0) Then
MsgBox &quot;You must enter your Login.&quot;
Exit Sub
End If

' Check to see if the user entered a password.
If (Len(document.loginpass.txtPassword.value) = 0) Then
MsgBox &quot;You must enter your Password.&quot;
Exit Sub
End If


'Tries to send login and password variables submited via form to the telnet client.

'Initialize variables
Dim txtLogin, txtPassword, wshshell
Set wshshell = CreateObject(&quot;WScript.Shell&quot;)
txtLogin = document.loginpass.txtLogin.value '<-???
txtPassword = document.loginpass.txtPassword.value '<-???

'Opens a connection to the server, must substitute a valid server address.
wshshell.Run &quot;telnet://127.0.0.1&quot;

'Wait for prompt before submitting text
varNow = Now
while DateDiff(&quot;s&quot;,varNow,Now) < 5
wend

'Send login value already submitted by user to telnet client via form when prompted by server
wshshell.SendKeys &quot;<%=txtLogin%>&quot; '<-???
wshshell.SendKeys &quot;{ENTER}&quot;

'Wait for prompt before submitting text
varNow = Now
while DateDiff(&quot;s&quot;,varNow,Now) < 5
wend

'Send password value already submitted by user to telnet client via form when prompted by server
wshshell.SendKeys &quot;<%=txtPassword%>&quot; '<-???
wshshell.SendKeys &quot;{ENTER}&quot;


' Confirm that authentication has been completed.
MsgBox &quot;Authentication complete.&quot;


End Sub

-->
</SCRIPT>

</HEAD>
<BODY>
<H1>User Authentication</H1>
<P>
To login please enter the following information:
</P>
<FORM NAME=&quot;loginpass&quot;>
<TABLE>
<TR>
<TD><B>Login:</B></TD>
<TD><INPUT TYPE=&quot;Text&quot; NAME=&quot;txtLogin&quot; SIZE=20></TD>
</TR>
<TR>
<TD><B>Password:</B></TD>
<TD><INPUT TYPE=&quot;Text&quot; NAME=&quot;txtPassword&quot; SIZE=20></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE=&quot;Button&quot; NAME=&quot;cmdConfigure&quot; VALUE=&quot;Configure&quot;>
</FORM>
</BODY>
</HTML>
 
Nevermind I figured it out. Thanks anyway.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top