C# Program to Execute a DOS Batch File

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 1490
using System;
using System.Diagnostics;

namespace ConsoleApplication1
class Program
static void Main(string[] args)
var exitCode = -1;
using (Process proc = new Process())
//Set the working directory for the process to be started
proc.StartInfo.WorkingDirectory = @"C:\";

//Set the doucment name to start
proc.StartInfo.FileName = "StartAppPool.bat";

//Execute the process

//Wait for the associated process to exit

//Gets the value of the associated process specified when it terminated.
exitCode = proc.ExitCode;

if(exitCode == 0) Console.WriteLine("Batch executed successfully");
else Console.WriteLine("Some problem happened while executing the batch program");


Comments or Responses

Login to post response