C#里面怎么单击执行bat文件
2013-07-11
如果你想看到bat的执行结果,最好在bat最后一句加上pause, 暂停.
添加一个按钮事件
执行下列代码:
using System.IO; //需要用的到dll
using System.Diagnostics;
// 实列化一个对象
ProcessStartInfo pro = new System.Diagnostics.ProcessStartInfo("cmd.exe");
pro.UseShellExecute = false;
pro.RedirectStandardOutput = true;
pro.RedirectStandardError = true;
pro.CreateNoWindow = true;
pro.Arguments = "/K " + System.Environment.CurrentDirectory + @"\net_create.bat";
pro.WorkingDirectory = System.Environment.CurrentDirectory;
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(pro);
System.IO.StreamReader sOut = proc.StandardOutput;
proc.Close();
string results = sOut.ReadToEnd().Trim(); //回显内容
sOut.Close();
2013-07-11