Hi
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;
batchProcess.Start();
Another way is
System.Diagnostics.Process.Start(@"C:\inetpub\wwwroot\Reboot\DB\Reboot.bat");
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;
listFiles.WaitForExit(2000);
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);
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;
p.Start();
p.WaitForExit();
Note:
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"
userName="Administrator"
password="xxxxxx"/>
</authentication>
pls reply asap
Regards Aravind