如何通过C#程序运行外部程序?

如何通过C#程序运行记事本或计算器等外部程序?

使用System.Diagnostics.Process.Start

可能重复: 如何从C#(WinForms)启动进程

也许它会帮助你:

System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); pProcess.StartInfo.FileName = @"C:\Users\Vitor\ConsoleApplication1.exe"; pProcess.StartInfo.Arguments = "olaa"; //argument pProcess.StartInfo.UseShellExecute = false; pProcess.StartInfo.RedirectStandardOutput = true; pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; pProcess.StartInfo.CreateNoWindow = true; //not diplay a windows pProcess.Start(); string output = pProcess.StandardOutput.ReadToEnd(); //The output result pProcess.WaitForExit(); 

嗨,这是调用Notepad.exe的示例控制台应用程序,请查看此内容。

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace Demo_Console { class Program { static void Main(string[] args) { Process ExternalProcess = new Process(); ExternalProcess.StartInfo.FileName = "Notepad.exe"; ExternalProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; ExternalProcess.Start(); ExternalProcess.WaitForExit(); } } } 

例如这样:

 // run notepad System.Diagnostics.Process.Start("notepad.exe"); //run calculator System.Diagnostics.Process.Start("calc.exe"); 

按照米奇回答中的链接。