Click here to Skip to main content
13,046,679 members (64,505 online)
Rate this:
Please Sign up or sign in to vote.
See more:
HI, I want to run a batch file in 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"
Label1.Text = "Batch file now started";
Posted 12-Jul-13 7:52am
Updated 12-Jul-13 8:00am
ThePhantomUpvoter 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100