Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI, I want to run a batch file in asp.net website on a server whenever a button clicked event is called,
I used following code , batch file running at debugging mode, but the batch file is not running after I hosted in web server. it does not giving any error also. kindly help.


String myBatchFileName = @"C:\test.bat"
System.Diagnostics.Process.Start(myBatchFileName);
Label1.Text = "Batch file now started";
Posted
Updated 12-Jul-13 8:00am
v2
Comments
[no name] 12-Jul-13 14:01pm    
You probably do not have permission to run batch files on your server and you probably do not have permission to access files on the root of the C drive on your server.

There are a number of things here.
The first is that (as ThephantomUpvoter says) you don't have permission to run it.

The second is more fundamental, I suspect. You do realise that C# code is executed on the server, not the client? So the batch file will run on the server, not the client, and affect server files, not client files. And the user will not be able to see anything the the batch file did, and would never know if it worked or not. It looked like it worked on your development system because the server and client are the same computer - so when you ran the batch file it worked on client file (because they were server files) and your user could see what was happening because he could see a server process.

I suspect you need to rethink your whole approach here!
 
Share this answer
 
On top of what other people have said, when run from ASP.NET, your batch file is being run by a service (IIS), which runs under it's own desktop, not the one you can see when you're logged into the server console. So, when the batch file runs, the CMD window that opens to run it is not visible to you. You can still see it in the Processes tab of Task Manager though. The only way you'll know what the batch file did, if anything was if you piped the output of the commands in the batch file to a file somewhere and read the file when the batch file was done.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900