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!

Wscript.shell.sendkeys

Status
Not open for further replies.

MrsMopey

Programmer
Jul 31, 2007
19
Hi,
I am trying to open a cmd prompt from an HTML page. I want to be able to log in to a telnet session, pass two variables from textboxes on the HTML form and execute a command. So far this is what I have:
Code:
<HTML>
<HEAD>
<TITLE>
Reset SX User
</TITLE>
<SCRIPT LANGUAGE="vbscript">
OPTION EXPLICIT

Sub cmdReset_OnClick

Dim txtUserID
Dim txtCoNo
Dim objShell

txtUserID = frmForm1.txtUserID.Value
txtCoNo= frmForm1.txtUserID.Value

Set objShell = CreateObject("wscript.Shell")

objShell.Run "%comspec% /k telnet volmrs"

objShell.SendKeys "root" [b][COLOR=red]<<<<< it stops here >>>[/color red][/b]
objShell.SendKeys "{ENTER}"
wscript.sleep(50)
objShell.SendKeys "fff"
wscript.sleep(100)
objShell.SendKeys "{ENTER}"
wscript.sleep(10)
objShell.SendKeys "Shut User " & txtCoNo & txtUserID
objShell.SendKeys "{ENTER}"


End Sub
</SCRIPT>
</HEAD>
<BODY BGCOLOR="white">
<FONT FACE="arial" SIZE=2><B>
<CENTER>
<H3>Reset SX User</H3>
<P>
Enter the UserID and Company number of the person you would like to reset in SX.
</P>
<FORM NAME="frmForm1">

User ID
<INPUT TYPE="text" NAME="txtUserID" SIZE=10>
<P>
<INPUT TYPE="button" NAME="cmdReset" VALUE="Reset">
<P>
Company Number
<INPUT TYPE="text" NAME="txtCoNo">
</FORM>
</BODY>
</HTML>

I can't get it to work. It stops after the first line. What am I doing wrong?

Thanks,


 
Well, thanks for the help but I just don't get what I am doing here at all. I thought this was going to be a simple little task, just code a bit of HTML and open a cmd prompt, then I start delving into the w3socket stuff and find out I can't script to a telnet window. So I am just to frustated to even try to continue. Besides that, I continue to get errors about ActiveX content, only way to avoid that is to drop the security down to LOW, I know the whole co. isn't going to do that. I am going to have to find another way to do this.

 
Why do you want to see a Telnet terminal window anyway? Isn't the whole point of this to put an HTML GUI on the front of a Telnet session?

As for the browser security popups maybe you'll want to create an HTA, not an HTM.

Seriously, nobody but hacks and the truly desperate use SendKeys. It is too problematic.


Another thing that bothers me is that this whole approach is terribly insecure. If users will have access to it anybody can do a "view source" and get the credentials to Telnet to that server themselves and wreak havoc.

An HTA probably won't help you anyway because you probably want this page served from a web server. Yes, you can source an HTA from a web server, but that has additional issues.

This (the Telnet operations you want done) probably would be best done server-side, from an ASP application. Unless you really goof up security on the VDir nobody will be able to see the user/pw for the Telnet server. That's actualy what the w3sockets library was made for.
 
Well thanks for the reply, I have started to build the ASP application, this is actually a rewrite of an existing intranet site that was quite poor. I don't want to see a telnet window when I am running these commands during production, but I do want to see what is going on during testing. Now, within ASP, what commands do I use to do the telnet'ing? I am connecting with a unix box.
 
You still need a component like w3sockets or similar.

If you want to trace the Telnet session during development, just Response.Write everything you send and receive via the Telnet client socket object.

To properly script the Telnet session you should start by manually performing the process via a Telnet client application, capturing everything to a text file (copy and paste if you have to). Try both working and failing scenarios. The session captures should give you the information you need to script a Telnet dialog, including what prompt text to WaitFor and what responses and commands to send.
 
I am connecting with a unix box
As you seem to want to simply execute a single command I suggest you, again, to use rsh.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That might be the answer, PHV. I still don't think you'd want to do it client-side though.
 
I still don't think you'd want to do it client-side though
I totally agree.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top