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

Executing Applications on a Server Through an ASP Page 1

Status
Not open for further replies.

topmac

Programmer
Nov 7, 2005
17
US
I am trying to invoke a batch file on the server using a link/button on a ASP web page.

I tried
Set WShShell = Server.CreateObject("WScript.Shell")
RetCode = WShShell.Run("C:\test1.bat")

-***-

Set Executor = Server.CreateObject("ASPExec.Execute")
Executor.Application = "cmd.exe"
Executor.Parameters = "/c c:\test1.bat"
Executor.ShowWindow = False
strResult = Executor.ExecuteWinApp

Neither of them work......
any ideas.....

thanks in advance,
_Uday
 
Your problem might be in using .run rather than .Exec.

You may not need to user Server.CreateObject since it is already executing in the servers context, though it may not make any difference.

Your second code relies on ASPExec being installed.

Remember also that the IUSR_machinename account will have to have execute permission on the bat file wherever it resides. And depending on what you are executing, the local machine ID may have to have permissions as well.

We just used a similar script to the one below for firing off a batch file to execute events on the database server so I know it works. The batch file executes based on the IUSR account but the program for firing events in the database requires that the computer itself have permission set in the database.


This code works.
Code:
Response.Buffer = true
  Set objWShell = CreateObject("WScript.Shell") 
  Set objCmd = objWShell.Exec("c:\test.bat") 
  strPResult = objCmd.StdOut.Readall() 
  set objCmd = nothing: Set objWShell = nothing 
 
  response.write strPResult

It executes the batch file and sends the response back to the screen.

Also, I have had problems with folder and filenames greater than 8 characters when executing with the Shell object so you have to truncate any long names to the 8.3 convention.
For instance: C:\Documents and Settings\myfile.bat
would have to be done as: C:\Docume~1\myfile.bat

You replace the long name with the first six characters, a tilde and a numerical reference.
The numerical reference is based on the alphabetic position of the name in the folder.
For instance if you have a folder "Documents and Settings"
and a folder "Documents of Mine" both would begin with Docume~ but the number would depend on which one comes first alphabetically.
Documents and Settings come before Documents of Mine alphabetically so Documents and Settings = Docume~1 and Documents of Mine = Docume~2.




Paranoid? ME?? WHO WANTS TO KNOW????
 
Works like a charm...!!
I can't thankyou enough for taking time to explain it clearly.

I have a request though...
Could you explain or throw some links that talk in detail about what you said...
"requires that the computer itself have permission set in the database."

I dont think I clearly understand what you mean (I do get the general idea about privelages for the account to run a process in the database)

If you could, that'll be great....
thanks again,
_Uday
 
The IUSR_machinename account has to have sufficient rights to access the shell object and invoke the bat file.
If the bat file is executing something outside of the IIS folders that program is executing under (I believe) the permissions of the System account on the server.

We were using the bat file to run an exe that tells the SQL server to start a job. The SQL server however will not run jobs for anyone, it looks at the permissions of the current user to see if that account has been granted permission to run the jobs. In this case the account in question is System so in the database we had to authorize System to run jobs on the SQL server.

So you are really looking at several layers of permissions.
Permissions on the server to execute the ASP code. Permissions on the server to allow the IUSR_machinname account access to the shell object. Permissions on the SQL server to authorize the IIS servers System account to execute the jobs.
Actually, I think there was one other thing we had to do.
I do not remember the name of the executable we had to run from the batch file but we had to give the System account permissions on that file as well.

I am not aware of any sites that explain this in detail, it is more a conglomeration of information I picked up from different places and trial and error on the server.
I am not certain it was the System account we dealt with either but if it becomes an issue for you I can follow up with my co-worker who worked with me setting this up.



Paranoid? ME?? WHO WANTS TO KNOW????
 
thanks a lot again man..!!
it was helpful.

I'll try to go over the steps I did in setting this process and play with the persmissions a little bit....
See if I can figure this out.... In case if I have any questions I'll post them here..!!

thanks a bunch again theniteowl,
_Uday
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top