C# 执行 .Bat文件

来源:互联网 发布:大数据的统计学基础炼 编辑:程序博客网 时间:2024/05/24 06:24

        string StarthwPath = Application.StartupPath + @"\scripts\start.bat";

 

        private void StartButton_Click(object sender, EventArgs e)
        {       
            this.RunBat(StartPath);
        }

 

private void RunBat(string batPath)
        {
            try
            {

                Process pro = new Process();

                FileInfo file = new FileInfo(batPath);

                pro.StartInfo.WorkingDirectory = file.Directory.FullName;

                pro.StartInfo.FileName = batPath;

                pro.StartInfo.CreateNoWindow = false;

                pro.Start();

                pro.WaitForExit();
            }
            catch (Exception)
            {
               
            }

        }

 

 

 

原创粉丝点击