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

ASP Novice - ASP / VBScript 1

Status
Not open for further replies.

ralisp

MIS
Apr 19, 2004
21
US
I have a simple VBScript that takes one parameter when called and then prompts the user to enter a second parameter to then call an exe. I need users to be able to run this exe on one server, so it's my understanding an option is to use ASP. How would I call this vbs in an ASP script? I thought as long as I enclose in <% %>, that would designate as a vbs script. Below is the code I want to use. Any help or suggestions would be appreciated.

Thanks...

Dim ArgObj

Set ArgObj = WScript.Arguments
Set WshShell = WScript.CreateObject("WScript.Shell")

nimid=ArgObj(0)

strRemTicket = InputBox ("Enter the Remedy Ticket:")
strcmd1 = "pu.exe -u user -p passwd nas assign_alarms TAC"
strCmd3 = " " & nimid
strCmd2 = " "& strRemTicket
strCmd = strCmd1 & strCmd2 & strCmd3
WshShell.run strCmd
 
What do you mean "run this exe on one server" ?

Does the user recieve a copy of the code from the web server and execute it? Or does the web server execute the code on behalf of a user?

I assume you want the second scenario but I'm uncertain. If so it will require significant syntactical changes.

 
Yes, the second scenario... I need to have multiple Clients pass an argument from their browser to run the same script on the host server. I'm assuming this will require the RUNAT="server" entry, but I'm unsure ofthe correct syntax. Thank you for your help.
 
Followup quesitons:
When the server executes the code, it does so in the security context of a particular user. Although the service usually runs as the local system account, by default all ASP is executed in the context of another local account named IUSR_MachineName. This account has very limited security rights on the web server and, since it is a local account, it has no permissions to anything else on your network.

Does this pu.exe program need to access another machine on your network? Is it OK for pu.exe to be run under a single shared account for all users or must it execute for each different user as if it was actually their account running the program?

The answers to these questions will determine if you need to make any changes to the IIS configuration.

Oh also it is very important that pu.exe not have any windows or anything that requires a mouse click or interaction with the desktop. If it can't be used solely from the command line then it is not a good candiate for conversion to ASP.

One last thing, you'll want to make an HTML form to be used to submit the user-supplied parameters. The VBScript pops up an Input box but clearly that is no good for running as an ASP because it requires typing something into a dialog window and we need things that can be run entirely from the command line.
 
The pu.exe runs on the same server that the asp runs on. The pu.exe is purely commanline and I pass the authentication to run the command, so no special Win permissions are needed. I will need to prompt the user on the client side for one aurgument..so in the end I a passing two parameters..one from user and one is passed by the calling applicaion on the client side.

Thanks again for your help...
 
OK the first guess is something like this:
Code:
<%
if Request("DoThePu") <> "" then
  Dim strcmd1
  Dim strcmd2
  Dim strcmd3
  Dim oShell

  strcmd1 = "pu.exe -u user -p passwd nas assign_alarms TAC" 
  strCmd2 = " " & Request("RemedyTicket")
  strCmd3 = " BlahBlahBlah"   '<-- something else here

  Set oShell = Server.CreateObject("Wscript.Shell")
  oShell.Run strCmd1 & strCmd2 & strCmd3
  set oShell = Nothing

  Response.Write "Done"
  Response.End
end if
%>
<html>
  <body>
    <form method="post">
      Remedy Ticket:
      <input type="text" name="RemedyTicket">
      <br>
      <input type="submit" name="DoThePu" value="Run Pu!">
    </form>
  </body>
</html>

I'm not sure what goes in [tt]strCmd3[/tt] it is the second parameter.

The way this design works is when the user initially requests the page from the server the ASP stuff inside the IF/THEN doesn't run and the user gets the HTML form. Then when the form is submitted, the meat of the ASP runs including the pu.exe. The code above just abruptly ends after running the pu.exe but you could optionally display some different HTML or redirect to another web page.
 
Remember that the design of that sample page requires the browser to request the page twice. The first one gets the HTML form the second submits the form and runs the pu.exe

So since the [tt]nimid[/tt] value comes in on the QueryString in the first request you'll need some method for passing it along with the second request.

One way to do this would be to embed the value of nimid into the HTML form as a hidden variable. Then the value will be re-submitted by the form and you can get the value in the same way you get the Remedy Ticket value entered into the textbox... like this:
Code:
<%
if Request("DoThePu") <> "" then
  Dim strcmd1
  Dim strcmd2
  Dim strcmd3
  Dim oShell

  strcmd1 = "pu.exe -u user -p passwd nas assign_alarms TAC" 
  strCmd2 = " " & Request("RemedyTicket")
  strCmd3 = " " & [highlight]Request("nimid")[/highlight]

  Set oShell = Server.CreateObject("Wscript.Shell")
  oShell.Run strCmd1 & strCmd2 & [highlight]strCmd3[/highlight]
  set oShell = Nothing

  Response.Write "Done"
  Response.End
end if
%>
<html>
  <body>
    <form method="post">
      Remedy Ticket:
      <input type="text" name="RemedyTicket">
      <br>
      [highlight]<input type="[red]hidden[/red]" name="nimid" value="<%= Request("nimid")%>">[/highlight]
      <input type="submit" name="DoThePu" value="Run Pu!">
    </form>
  </body>
</html>
 
Thanks for all your help! Appreciate you sticking with me on this, it's working as I had hoped and I have a much better understanding of the process now. Happy Holidays.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top