执行批处理文件

private void RunBat(string batPath)
{
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();
}
 
Process proc = new Process(); 
proc.StartInfo.FileName = @"D:\Program Files\Foxmail\Foxmail.exe"; //可以用绝对路径  也可以是BAT文件
proc.StartInfo.Arguments = ""; 
proc.Start();
 
 
Process process = new Process();//实例
        process.StartInfo.CreateNoWindow = true;//设定不显示窗口
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.FileName = "cmd.exe"; //设定程序名  
        process.StartInfo.RedirectStandardInput = true;   //重定向标准输入
        process.StartInfo.RedirectStandardOutput = true;  //重定向标准输出
        process.StartInfo.RedirectStandardError = true;//重定向错误输出
        process.Start();
        process.StandardInput.WriteLine("ipconfig");//执行的命令
        process.StandardInput.WriteLine("exit");
        process.WaitForExit();
        process.Close();
        return process.StandardOutput.ReadToEnd();
 
posted @ 2012-11-14 11:37  717806198  阅读(209)  评论(0编辑  收藏  举报