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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run .vbs from ASP Page 1

Status
Not open for further replies.

cwsstins

MIS
Aug 10, 2004
412
US
I've got an .asp page with an image on it. I want users to be able to click the image and run a .vbs file, without getting the "Open, Save, or Cancel" File Download prompt.

I've got a vbs sub:
Code:
<script language="text/vbscript">  
  Sub PwdReset()
    Set wshshell=createobject("wscript.shell")
    wshshell.run "PasswordReset.vbs"
    Set wshshell=Nothing
  End Sub
</script>

Then the image is like this:
<img src="\\server\directory\image.jpg" onClick="vbscript:pwdReset()">

When I click the image, nothing happens.

If I run:
Code:
    Set wshshell=createobject("wscript.shell")
    wshshell.run "PasswordReset.vbs"
    Set wshshell=Nothing

by itself in a stand-alone .vbs file, it works. What's the problem?

stinsman
 
What?

You think I carefully read the problem?

Naw. I just skimmed it. Is it Friday yet?
 
I believe what is going on is that you (a web server) can not execute a script (program, script, pif, anything) located on a user's (the client) hard drive.

=====================
Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 
what if you forget that vbs if all your trying to do is reset password, just try something like this

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
function resetpass(strchar)
Randomize()
PassLen = 0
CurrPass = ""

do while PassLen < strchar
CurrLtr = Int((42 * Rnd()) + 48)
if CurrLtr < 57 or CurrLtr > 65 then
CurrPass = CurrPass & Chr(CurrLtr)
PassLen = PassLen + 1
end if
loop
resetpass=CurrPass
end function 

if request("change")="y" then

newpass=resetpass(8)
'do something with it, save to db, etc
' 
end if
%>


<HTML>

<head>
<LINK REL="stylesheet" TYPE="text/css" HREF="..\CS_Pwd.css">

<title>Password Reset</title>

<center><img src="..\heatceylogo.gif"></center>

<h2>
Password Reset
</h2>
<P>

Click the image below to reset your password:

<P>

<center><a href="thispage.asp?change=y"><img src="\\server\directory\Padlock.jpg"></a></center>

<P>

<hr>

<P>

<BR><BR><BR><BR><BR>

<center><p><A HREF="" onClick="window.close()"><H4><img src="..\Close.gif" border=0 ALT="Close this Window"></A></p></center>

</font>
</body>
</HTML>
 
But the script is located on a server, not a client. The .asp page is located on a webserver. I've tried it with the .vbs in the same directory on the webserver, as well as with an absolute path to a share on another server.

As far as the password change itself, this is for an application that uses an encrypted password. So in order to tell the user what their new password is, I had to set up cases in vbs. If the encrypted pwd = gghdh, then tell the user what gghdh equals.
 
Cannot be sure this can be done: src="\\server\directory\...". I think not. But as we do not care any more what constitute a well-posed problem, what can I say?!
 
could this not be done like this -- click on the image and instead of it calling a client-side vbscript to run a .vbs it calls a new page. and on the new page, the .vbs is called and run server-side and the result sent to the screen, encrypted. i haven't tried it or anything but it seems logical.
 
So the bottom line is, all you need to do is unencrypt the password and show the result to the user?

Heck yeah do this on the server!

If you try to do it on the client then every client will get a copy of the code that defeats your encryption scheme...

[elephant2][elephant2][elephant2][elephant2]


 
OK, how do I set it to run at the server? I tried earlier, per Steven290's runat=server and received this error: The scripting language 'text/vbscript' is not found on the server.

Does this mean that my webserver does not allow vbscript at all? If so, this may be a moot point...
 
No, what you want to do is to take the script out of the .VBS file and put in into an ASP instead. Return the value directly from the ASP.
 
Wouldn't that mean converting the 250+ lines of vbs code into asp?

 
it seems like you should be able to put the call to the .vbs in the asp code instead of client-side vbscript. so create the new page that is called by the image-click, dump the call to the .vbs into it and then pretty it up later.
 
Wouldn't that mean converting the 250+ lines of vbs code into asp?

Ah but you can use VBScript in ASP so it is only a matter of changing some minor things like CreateObject() --> Server.CreateObject()
 
ethorn's idea worked, but now I have another problem. I guess this .vbs would have to run client-side because it performs a create filesystemobject to set up an email on the client's Lotus Notes file.

My image opens another .asp file (per ethorn's suggestion), which contains this line: <script language="vbscript" src="PasswordReset.vbs"></script>

So the page opens and the script begins running. However, as soon as it tries to create the filesystemobject, this error appears, I suppose because it's trying to run on the server:

Could not Create FileSystemObject

I should probably just pack it in on this one...thanks to everybody for your time and ideas.
 
No reason you can't send email from the server.. whatever you do don't send the decryption code to the client.

This will send it to the client: <script language="vbscript" src="PasswordReset.vbs"></script>

... just look in your browser cache to see.
 
Ah, but we don't have the sendmail utility running on our webservers. I don't know the reason behind that...

I see what you mean about running it from the client. Seems like my best option is to find another way for users to run this .vbs file.

thanks,
stinsman
 
spend the time converting it to a .asp file. it shouldn't take too long. there should only be a few discrepencies in the code, like Sheco pointed out with the createobject.
 
I'm afraid I'm not that well versed in asp (or vbs for that matter), as you can probably tell. Might take a little longer than you think : )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top