How to run an external application through a C# application?

An external application can be run from a C# application using the Process class. A process is a program that is running on your computer. This can be anything from a small background task, such as a spell-checker or system events handler, to a full-blown application like Notepad.

Each process provides the resources needed to execute a program and is started with a single thread, known as the primary thread. Processes are heavily dependent on system resources, while threads require minimal resources. The Process class is present in the System.Diagnostics namespace.

Syntax

Following is the basic syntax for starting an external process −

Process processName = new Process();
processName.StartInfo.FileName = "application.exe";
processName.Start();

You can also use the static method for simple cases −

Process.Start("application.exe");

Using Process.Start() with Application Path

The following example demonstrates how to run Notepad from a C# application −

using System;
using System.Diagnostics;

namespace DemoApplication {
    class Program {
        static void Main() {
            Process notepad = new Process();
            notepad.StartInfo.FileName = "notepad.exe";
            notepad.StartInfo.Arguments = "DemoText.txt";
            notepad.Start();
            
            Console.WriteLine("Notepad started successfully!");
            Console.WriteLine("Press any key to continue...");
        }
    }
}

The output of the above code is −

Notepad started successfully!
Press any key to continue...

Using Process.Start() with URLs

You can also open URLs in the default browser using the static Process.Start() method −

using System;
using System.Diagnostics;

namespace DemoApplication {
    class Program {
        static void Main() {
            Process.Start("https://www.google.com/");
            Console.WriteLine("Browser opened with Google!");
            Console.WriteLine("Application completed.");
        }
    }
}

The output of the above code is −

Browser opened with Google!
Application completed.

Advanced Process Configuration

For more control over the external process, you can configure additional properties −

using System;
using System.Diagnostics;

namespace DemoApplication {
    class Program {
        static void Main() {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/c echo Hello from external process!";
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.CreateNoWindow = true;
            
            Process process = Process.Start(startInfo);
            string output = process.StandardOutput.ReadToEnd();
            process.WaitForExit();
            
            Console.WriteLine("External process output: " + output);
            Console.WriteLine("Process completed with exit code: " + process.ExitCode);
        }
    }
}

The output of the above code is −

External process output: Hello from external process!

Process completed with exit code: 0

Common Properties and Methods

Property/Method Description
FileName Specifies the application or document to start
Arguments Command-line arguments to pass to the application
UseShellExecute Whether to use the operating system shell to start the process
WaitForExit() Waits for the process to exit before continuing
ExitCode Gets the exit code of the process

Conclusion

The Process class in C# provides a powerful way to run external applications from your programs. You can use simple static methods for basic scenarios or configure detailed process settings for advanced control over execution, output redirection, and process monitoring.

Updated on: 2026-03-17T07:04:36+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements