Click here to Skip to main content
Click here to Skip to main content

Using Diagnostics.Process to start an external application.

, 4 Jun 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
This is a beginner-level article to show how to start an external application from C#.


A very basic thing that is usually required for programmers, is to start an external process from your application. This may be a simple call to Notepad.exe to let the user view your Readme.txt file, or it may be some complex project.

I recently had to use these facilities to install a Windows service. This complicated matters, since I also needed the environment variable required for the Windows Path.

After a bit of searching in the .NET libraries, I found that I needed no Windows API call to CreateProcess like I used to do when I was using C++.

The .NET framework includes a class called Process, and it is included in the Diagnostics namespace.

All you need to do is to include the namespace, using System.Diagnostics;, and at the place where you wish to start the application, call the Process.Start method, like so:

Process.Start("notepad", "readme.txt");

I wanted to create a service, and the executable path could not include a string like "%windir%";, so I had a long search before I discovered the Environment class in the .NET framework. To install my service, I could then call the Installutil application that is included in the .NET folder, like so:

string winpath = Environment.GetEnvironmentVariable("windir");
string path = System.IO.Path.GetDirectoryName(

Process.Start(winpath + @"\Microsoft.NET\Framework\v1.0.3705\Installutil.exe",
    path + "\\MyService.exe");

The above illustrates how the Diagnostics.Process class eases the task of creating a process. The Start method returns a process, so you can inspect its properties after it started.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) DigiCore Technology
South Africa South Africa
Software developer

Comments and Discussions

QuestionStart external process Pinmembernaveen ranjan21-Mar-14 23:10 
QuestionProcess.Start() ... NOT STARTED ??? PinmemberEkvilibrium16-Jan-10 8:06 
GeneralMy vote of 2 Pinmembertitwan3-Dec-08 6:12 
Generaldoc 2 pdf PinmemberAli Ghazaei6-Oct-08 11:13 
GeneralShell to use PDF printer PinmemberAli Ghazaei28-Sep-08 14:06 
Questionhow to use parameter PinmemberMember 372990228-Aug-08 21:06 
GeneralDifferent article/good job PinmemberSamuel Allen7-Jun-08 14:37 
GeneralMy external App is not finishing Pinmemberliorjj20-Oct-07 23:22 
QuestionHow to start an application in foreground PinmemberAbdul Hasib2-Jul-07 2:18 
AnswerRe: How to start an application in foreground Pinmembernekropatolog26-Aug-07 22:36 
QuestionProcess.Start("Notepad.exe") from Service. PinmemberKent Keller3-Apr-07 14:05 
QuestionRe: Process.Start("Notepad.exe") from Service. Pinmemberauxcom25-May-08 16:14 
QuestionTo call a program PinmemberalexTCT17-Oct-06 15:52 
QuestionHow to use runas ? PinmemberRedaemon20-Jan-06 7:24 
Questionan funny problem Pinmembermostafa.hk13-Jan-06 19:25 
QuestionWhat about starting a process as a different user? Pinmemberwyatt blake4-Oct-05 2:14 
GeneralBackground UI PinmemberZenlander30-Jun-05 21:34 
GeneralRe: Background UI PinmemberITGFanatic6-Mar-07 13:00 
GeneralRunning external application in .Net CF PinsussVasil Zhekov13-Oct-04 5:16 
GeneralRe: Running external application in .Net CF PinmemberCRoberto4-Feb-05 3:32 
GeneralRunning the process inside the application PinmemberMesrop Simonian27-Feb-04 12:47 
GeneralAbsoute paths PinmemberNameOfTheDragon11-Jun-03 1:38 
GeneralRe: Absoute paths PinmemberWillemSe11-Jun-03 7:58 
GeneralRe: Absoute paths Pinmember94stangfan16-Aug-04 13:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 5 Jun 2003
Article Copyright 2003 by WillemSe
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid