C# 调用bat文件

引入名称空间:

using System.Diagnostics;

 

Process proc = null;
try
{
string targetDir = string.Format(@"D:\BATFile\");//this is where testChange.bat lies
proc = new Process();
proc.StartInfo.WorkingDirectory = targetDir;
proc.StartInfo.FileName = "Video.bat";
proc.StartInfo.Arguments = string.Format("20");
//proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//这里设置DOS窗口不显示,经实践可行
proc.Start();
proc.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
}

posted @ 2017-08-30 16:01  dogxuefeng  阅读(2179)  评论(0编辑  收藏  举报