日期:2014-05-19  浏览次数:20951 次

C#中如何使用Process,Start()使一个无gui的exe在后台启动
RT

比如
在cmd模式下可以使用   start/b   abc.exe   -argument

请问在C#中如何实现??

------解决方案--------------------
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
//设置外部程序名
Info.FileName = "notepad.exe ";
//设置隐藏窗口
Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//设置外部程序的启动参数(命令行参数)为test.txt
Info.Arguments = "test.txt ";
//设置外部程序工作目录为 C:\
Info.WorkingDirectory = "C:\\ ";
//声明一个程序类
System.Diagnostics.Process Proc;
try
{
//
//启动外部程序
//
Proc = System.Diagnostics.Process.Start(Info);
}
catch (System.ComponentModel.Win32Exception exc)
{
Console.WriteLine( "系统找不到指定的程序文件。\r{0} ", exc);
return;
}

------解决方案--------------------
//设置隐藏窗口
Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

够清晰不?
------解决方案--------------------
Process.Start( "cmd ", "/c start/b abc.exe -arguments ")
------解决方案--------------------
同意楼上
------解决方案--------------------
http://faq.csdn.net/read/208497.html
------解决方案--------------------

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Process myProcess;
private void button1_Click(object sender, System.EventArgs e)
{
try
{
if(textBox1.Text.Length != 0)
{
myProcess = Process.Start(textBox1.Text);
myProcess.WaitForExit();
}
}
catch (Exception ee)
{
richTextBox1.Text += "异常: "+ee.ToString()+ "\n ";
}
}

private void button2_Click(object sender, System.EventArgs e)
{
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
}
------解决方案--------------------
System.Diagnostics.ProcessStartInfo ps = new ProcessStartInfo( "Ping.exe " , "127.0.0.1 " );
ps.UseShellExecute = false;
ps.CreateNoWindow = true;//加这一句
ps.RedirectStandardOutput = true;
Process p= Process.Start(ps);
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
this.textBox1.Text = output;

------解决方案--------------------
start是Command模式下的扩展命令,所以必须在cmd后加参数/c指示的执行/c后的命令.