Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:

How to run or execute batch file from ASP.Net,i am written bath file for restart the server machine

and my batch file line is "shutdown /r /t 5".If i run bath file manually it will restart ¬

machine,but if i use ASP.Net nothing happen,simply page get refresh not restart machine i will use

3 to 4 types of codings,below is code

string str_Path = Server.MapPath(".") + "\\DB\\Reboot.bat";

ProcessStartInfo processInfo = new ProcessStartInfo(str_Path);

processInfo.UseShellExecute = false;

Process batchProcess = new Process();

batchProcess.StartInfo = processInfo;


Another way is


Another way is

System.Diagnostics.ProcessStartInfo psi =

new System.Diagnostics.ProcessStartInfo(@"C:\inetpub\wwwroot\Reboot\DB\Reboot.bat");

psi.RedirectStandardOutput = true;

psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

psi.UseShellExecute = false;

System.Diagnostics.Process listFiles;

listFiles = System.Diagnostics.Process.Start(psi);

System.IO.StreamReader myOutput = listFiles.StandardOutput;


if (listFiles.HasExited)


string output = myOutput.ReadToEnd();

TextBox1.Text = output;


Another way

string filepath = "C:\\inetpub\\wwwroot\\Reboot\\DB\\Reboot.bat";

System.Diagnostics.Process.Start(filepath); //Provided the name and path is correct

Another way

Process p = new Process();

p.StartInfo.WorkingDirectory = @"C:\Inetpub\wwwroot\Reboot\DB\";

p.StartInfo.FileName = "Rebooot.bat";

p.StartInfo.Arguments = string.Format("{0},{1}", param1, param2);

p.StartInfo.CreateNoWindow = false;




i have save batch file inside root folder (i.e inside website root folder in iis) "C:

\inetpub\wwwroot\Reboot\DB\Reboot.bat" if i copy and paste this path in windows explorer address ¬

bar it run batch file and system restarted

I know above are all same,but not execute batch file.Need to enable and permission in website or need to add impersonate as true ?

but i give all premission for root folder,and give impersonate as True with username and password

<authentication mode="Windows">

<identity impersonate="true" 




pls reply asap

Regards Aravind
Updated 26-Jul-14 16:20pm
Thanks7872 26-Jul-14 14:59pm    
And what that all comments mean? d? s? What was that?
Aravindba 20-Jul-15 22:59pm    
sorry why it display like d and s,i dont know,actually i delete my comments,after delete my comments it look like d and s dont know
Sergey Alexandrovich Kryukov 26-Jul-14 16:15pm    
Are you serious? The name "reboot.bat" suggests that you want to reboot the host running an HTTP server on the client request. Do you really want it? Why?
Aravindba 26-Jul-14 22:17pm    
Hi SA,this is web application used in intranet,so once change ip,subnet,gateway need to restart machine,this only it affect new ip config when system in logoff state,if it logon then no problem

1 solution

It sounds like a permission issue.

You may just want to change the identity on the application pool where your site is to an account ¬

that has the permissions.
Share this answer
ZurdoDev 26-Jul-14 11:20am    
Set the app pool identity to the administrator account you have in your web.config.
ZurdoDev 26-Jul-14 11:34am    
I don't understand what you are asking.

Go into IIS, just like your screen shot showed, and change the identity to the administrator account you are using in the web.config instead of using the account LocalSystem.
ZurdoDev 26-Jul-14 11:42am    
No, it is not a built in account. So don't choose the built-in account. Your question showed that you were trying to impersonate the administrator account so just use that account in your app pool.
ZurdoDev 26-Jul-14 12:05pm    
You need an account that has permissions. If you granted your administrator account the proper permissions then use that one. Perhaps you should read It is from the previous version of IIS but this is actually very simple. You need an account with the proper permissions and then set the app pool to use that account.
ZurdoDev 26-Jul-14 12:35pm    
I don't know how to explain it any other way. You even posted a screen shot where all you have to do is put in an account that has permissions.

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