Please help. Run batch file on server from asp.net page

P

Paul

Hi,

I'm trying to add a button to an asp.net page that when clicked will
run a batch file on the server. My code which gets executed on the
click event of my button is as follows

Dim ProcessStartInfo As New System.Diagnostics.ProcessStartInfo()
ProcessStartInfo.FileName = "C:\Inetpub\wwwroot\myapp\do.bat"
ProcessStartInfo.WorkingDirectory = "C:\Inetpub\wwwroot\myapp\"
ProcessStartInfo.UseShellExecute = True
ProcessStartInfo.CreateNoWindow = True
System.Diagnostics.Process.Start(ProcessStartInfo)

The batch file unzips a file which is located in the working directory
into the same directory. The executable that is called by the batch
file (which does the unzipping) is also in this directory. I've tested
my batch file by running it in a DOS window and it does what is
expected. However when I execute the code from the asp.net page
nothing works but I don't get an error. (I know that the code is
getting executed because I have stepped through it and when I change
the FileName property to a fictitious value I get an error). I've
tried various combinations of the above i.e. trying to running cmd.exe
passing in the bat file name as ProcessStartInfo.Arguments value,
setting various values for the ProcessStartInfo.WindowStyle etc. I've
given aspnet_wp account full control permissions on all directories I
think may be necessary (e.g. the working directory above, my windows
installation directory when I tried calling cmd.exe etc.). I'm still
sure it has something to do with permissions. If somebody could help
me out I'd be grateful. I know that executing something on the server
is not a good idea and believe me when I say this is not my preferred
approach but I just want to get it working at this stage.

Thanks,

Paul
 
D

Dennis Homann

Hi Paul,

have you tried to set your filename to

ProcessStartInfo.FileName = "cmd C:\Inetpub\wwwroot\myapp\do.bat"

I'm not sure, if this will solve your problem, but it should be worth a try.

Regards,
Dennis
 
P

Paul

Hi Dennis,

Thanks for the reply. I haven't tried that exact combination. I'll
give it a go but I think its something else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top