C# 用process运行一个程序,并得到返回值,为什么无法隐藏那个黑色的cmd窗体

来源:百度知道 编辑:UC知道 时间:2024/05/31 20:38:48
C# 用process运行一个程序rasdial.exe,并得到返回值,每次运行时,都会闪出一个cmd运行窗体, p.StartInfo.WindowStyle = system.Diagnostics.ProcessWindowStyle.Minimized;也还是不能隐藏,怎么回事
public string DisALlConnect()
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "rasdial";
p.StartInfo.Arguments = "/disconnect";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
p.Start();
p.WaitForExit();
return p.StandardOutput.ReadToEnd();
}

p.Start();
p.WaitForExit(1000);
p.Close();
return p.StandardOutput.ReadToEnd();
加个p.Close();试试,我的是直接就消失的

public string DisALlConnect()
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "rasdial";
p.StartInfo.Arguments = "/disconnect";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();
return p.StandardOutput.ReadToEnd();
}