48

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

3
  • 4
    Welcome to Stack Overflow. I think it's safe to assume that English is your second language. To increase your chances of getting an answer, I would re-write the question title to say "How to open an external program from a C# program?". Also is it a Console App, Winforms, Web(hopefully not)? Provide a little more information, and make sure you check out the Stack Overflow FAQ. Commented Jul 4, 2010 at 5:09
  • @Michael I assume hw is simply how. Commented Jul 4, 2010 at 5:11
  • 2
    Possible duplicate of How do I start a process from C#? Commented Nov 9, 2016 at 0:27

4 Answers 4

64

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();
}
Sign up to request clarification or add additional context in comments.

Comments

31

Use System.Diagnostics.Process.Start

3 Comments

FYI "Example" is a dead link. Always the drawback when specifying links.
Maybe it is just my failing eyesight then
Not dead in the sense that it doesnt lead anywhere, dead in the sense that it doesnt actually show an example.
15

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();
        }
    }
}

Comments

14

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.