C#中启动外部应用程序

时间:2022-09-20 22:36:34

C#中我们可以通过Process类直接启动外部应用程序

代码如下:

Process p = new Process();
                    p.StartInfo.FileName = "cmd.exe"; //打开cmd
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardInput = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.RedirectStandardError = true;
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.Arguments = "/c "+"ping baidu.com“;//给打开的程序设置参数

p.Start();
                    p.Close();
                    p.Dispose();