码迷,mamicode.com
首页 > Windows程序 > 详细

C# 执行批处理文件(*.bat)的方法代码

时间:2015-06-29 16:39:02      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

代码如下:

static void Main(string[] args)
{
    Process proc = null;
    try
    {               
        string targetDir = string.Format(@"D:\adapters\setup");//this is where mybatch.bat lies
        proc = new Process();
        proc.StartInfo.WorkingDirectory = targetDir;
        proc.StartInfo.FileName = "mybatch.bat";
        proc.StartInfo.Arguments = string.Format("10");//this is argument
        proc.StartInfo.CreateNoWindow = false;
        proc.Start();
        proc.WaitForExit();
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception Occurred :{0},{1}", ex.Message,ex.StackTrace.ToString());
    }
}


如果要运行时隐藏dos窗口,需使用下面的代码

 

 

复制代码 代码如下:

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

C# 执行批处理文件(*.bat)的方法代码

标签:

原文地址:http://www.cnblogs.com/aiqingqing/p/4607638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!