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
 
did you try

Code:
<script language="vbscript" runat="server">  
  Sub PwdReset()
    Set wshshell=createobject("wscript.shell")
    wshshell.run "PasswordReset.vbs"
    Set wshshell=Nothing
  End Sub
</script>
 
Steven, thanks for the reply...I just tried that and now the page won't load at all, with the error: <i>The scripting language 'text/vbscript' is not found on the server.</i>

I don't have any control over the web server here and it would take an act of Congress to get anything changed, so I better stick with running at the client level.

But why would this work if the sub is written in its own .vbs, and not in this page? Is there a problem with the way I'm calling it through the onclick?
 
Try changing your onClick to this:
Code:
<img src="\\server\directory\image.jpg" onClick="PwdReset">


=====================
Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 
Dennis, I just tried that with the same results.

I tried changing the sub to just a msgbox and it works with the onclick="vbscript:CallScript()"

So is there a problem with my sub procedure?
Code:
<script language="text/vbscript">  
  Sub PwdReset()
    Set wshshell=createobject("wscript.shell")
    wshshell.run "PasswordReset.vbs"
    Set wshshell=Nothing
  End Sub
</script>
 
I believe you need the "server."
Code:
set wshshell = server.createobject("wscript.shell")
Sorry I missed that on the first go-around!
-Dennis


=====================
Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 
Nada. Maybe I need to just deal with "File Download" window...

Thanks for your responses.

stinsman
 
Try changing your wshshell.run command to this:
Code:
wshshell.run ("%comspec% /c PasswordReset.vbs", 0, True)


=====================
Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 
Dennis, I tried it...when the .asp page loads, I get this error:

Line: 23
Error: Cannot use parentheses when calling a sub

Clicking the image still does nothing.

Line 23 is:

Set wshshell=createobject("wscript.shell")
 
to fixx this

Cannot use parentheses when calling a sub

try calling it like this

call wshshell.run("%comspec% /c PasswordReset.vbs", 0, True)

or

wshshell.run "%comspec% /c PasswordReset.vbs", 0, True
 
Steven, both of those worked to remove the error when the page loads. But clicking the image still does nothing. Again, if I change the sub to msbox "test" a message box appears when I click the image.
 
There is a big confusion/uncertainty where actually is the .vbs and where the script is supposed to run. Clear those up will make you think clearer.
 
Is the vbs supposed to run on the client's machine using a file located on the server?

Or is it supposed to run in the user's context on the server?
 
Sheco, it is supposed to be a server-residing file that runs on the user's client. If I run the .vbs on its own, that's what happens.

Steven, here's my entire code for the .asp page. Are you talking about the code for the .vbs file? I can post that, but it's a 250+ lines of code.

Code:
<HTML>

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

<title>Password Reset</title>

<script type="text/vbscript">

  Sub PwdReset()
    Set wshshell=createobject("wscript.shell")
    wshshell.run "%comspec% /c PasswordReset.vbs", 0, True
    Set wshshell=Nothing
  End Sub

</script>

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

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

Click the image below to reset your password: 

<P>

<center><img src="\\server\directory\Padlock.jpg" onClick="vbscript:PwdReset()"></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>
 
Does this work?

stinsman.htm
Code:
<HTML>
 <head>
  <title>Password Reset</title>
  <script type="text/vbscript" src="foo.vbs"></script>
 </head>

 <body>
  <h2>
    Password Reset
  </h2>

  Click the button below to reset your password: 
  <BR>
  <input type="button" value="Click here!" onClick="vbscript:Foo()">
 </body>
</HTML>


foo.vbs
Code:
sub Foo()
 Randomize
 msgbox Int(rnd * 100000),,"Hi Stinsman"
End Sub
 
But the vbs is now on the client machine already.
 
Well it will get there anyway if he goes with the download method.
 
Will it? Not without changing the given of the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top