Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET batch
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 12-Jul-13 8:52am
Edited 12-Jul-13 9:00am
v2
Comments
ThePhantomUpvoter at 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
good
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!
  Permalink  
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 Mathew Soji 315
2 Shweta N Mishra 269
3 BillWoodruff 240
4 OriginalGriff 235
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,988
3 Manas Bhardwaj 4,539
4 Maciej Los 3,775


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 12 Jul 2013
Copyright © CodeProject, 1999-2014
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