How to run external program via a C# program?

前端 未结 4 1744
旧时难觅i
旧时难觅i 2020-11-30 05:25

How do I run an external program like Notepad or Calculator via a C# program?

相关标签:
4条回答
  • 2020-11-30 06:00

    Hi this is Sample Console Application to Invoke Notepad.exe ,please check with this.

    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();
            }
        }
    }
    
    0 讨论(0)
  • 2020-11-30 06:10

    For example like this :

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

    Follow the links in Mitchs answer.

    0 讨论(0)
  • 2020-11-30 06:21

    Use System.Diagnostics.Process.Start

    0 讨论(0)
  • 2020-11-30 06:26

    Maybe it'll help you:

    using(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();
    }
    
    0 讨论(0)
提交回复
热议问题