Execute Batch File

Execute Batch File

- First of all you need to write all the commands in the Batch File.
- Launch a command shell that navigates to the directory where the batch file
- Execute all the commands in the Batchfile

- strPath will be targetDir of the Application
- BatchfileName will be like batchFileName = "\\ServiceInstaller.bat"

ProcessStartInfo cmdProcessInfo;
string driveLetter = strPath.Substring(0, strPath.IndexOf("\\") + 1);
cmdProcessInfo = new ProcessStartInfo("cmd.exe");
cmdProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmdProcessInfo.Arguments = "/c cd /d " + driveLetter + "&& cd " + strPath + "&&" + batchFileName.Split(@"\".ToCharArray(), 2)[1];
Process cmdProcess = Process.Start(cmdProcessInfo);
if (cmdProcess != null)
if (!cmdProcess.HasExited)


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: