展开全部
C#中执行批处理文件(*.bat)的方法。
实现代码如下:
using System.IO;
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();
如果要运行时隐藏dos窗口,需使用下面的代码
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
实现代码如下:
using System.IO;
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();
如果要运行时隐藏dos窗口,需使用下面的代码
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询