本来准备用封装好的可以执行cmd命令的方法执行.bat的,但是总是有问题,后来找了点资料,自己写了一个方法执行.bat
1 2 3 4 5 6 7 8 9 10 11 | public static void RunBat(String batAddress) { Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.FileName = batAddress; process.StartInfo.UseShellExecute = true; process.StartInfo.CreateNoWindow = false; process.Start(); process.WaitForExit(); } |
关键在于把UseShellExecute设置成true。