Click here to Skip to main content
15,443,778 members
Articles / Programming Languages / C#
Posted 4 Jun 2003


46 bookmarked

Using Diagnostics.Process to start an external application.

Rate me:
Please Sign up or sign in to vote.
3.35/5 (39 votes)
4 Jun 2003CPOL1 min read
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)

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

Comments and Discussions

QuestionStart external process Pin
naveen ranjan21-Mar-14 22:10
Membernaveen ranjan21-Mar-14 22:10 
QuestionProcess.Start() ... NOT STARTED ??? Pin
Ekvilibrium16-Jan-10 7:06
MemberEkvilibrium16-Jan-10 7:06 
GeneralMy vote of 2 Pin
titwan3-Dec-08 5:12
professionaltitwan3-Dec-08 5:12 
Generaldoc 2 pdf Pin
Ali Ghazaei6-Oct-08 10:13
MemberAli Ghazaei6-Oct-08 10:13 
GeneralShell to use PDF printer Pin
Ali Ghazaei28-Sep-08 13:06
MemberAli Ghazaei28-Sep-08 13:06 
Questionhow to use parameter Pin
KashyapPatel28-Aug-08 20:06
MemberKashyapPatel28-Aug-08 20:06 
GeneralDifferent article/good job Pin
Samuel Allen7-Jun-08 13:37
MemberSamuel Allen7-Jun-08 13:37 
GeneralMy external App is not finishing Pin
liorjj20-Oct-07 22:22
Memberliorjj20-Oct-07 22:22 
QuestionHow to start an application in foreground Pin
Abdul Hasib2-Jul-07 1:18
MemberAbdul Hasib2-Jul-07 1:18 
AnswerRe: How to start an application in foreground Pin
nekropatolog26-Aug-07 21:36
Membernekropatolog26-Aug-07 21:36 
QuestionProcess.Start("Notepad.exe") from Service. Pin
Kent Keller3-Apr-07 13:05
MemberKent Keller3-Apr-07 13:05 
QuestionRe: Process.Start("Notepad.exe") from Service. Pin
auxcom25-May-08 15:14
Memberauxcom25-May-08 15:14 
QuestionTo call a program Pin
alexTCT17-Oct-06 14:52
MemberalexTCT17-Oct-06 14:52 
QuestionHow to use runas ? Pin
Ariston Darmayuda20-Jan-06 6:24
MemberAriston Darmayuda20-Jan-06 6:24 
Questionan funny problem Pin
mostafa.hk13-Jan-06 18:25
Membermostafa.hk13-Jan-06 18:25 
QuestionWhat about starting a process as a different user? Pin
wyatt blake4-Oct-05 1:14
Memberwyatt blake4-Oct-05 1:14 
GeneralBackground UI Pin
Zenlander30-Jun-05 20:34
MemberZenlander30-Jun-05 20:34 
GeneralRe: Background UI Pin
ITGFanatic6-Mar-07 12:00
MemberITGFanatic6-Mar-07 12:00 
GeneralRunning external application in .Net CF Pin
Zhekov13-Oct-04 4:16
MemberZhekov13-Oct-04 4:16 
GeneralRe: Running external application in .Net CF Pin
CRoberto4-Feb-05 2:32
MemberCRoberto4-Feb-05 2:32 
GeneralRunning the process inside the application Pin
Mesrop Simonian27-Feb-04 11:47
MemberMesrop Simonian27-Feb-04 11:47 
GeneralAbsoute paths Pin
NameOfTheDragon11-Jun-03 0:38
MemberNameOfTheDragon11-Jun-03 0:38 
GeneralRe: Absoute paths Pin
WillemSe11-Jun-03 6:58
MemberWillemSe11-Jun-03 6:58 
GeneralRe: Absoute paths Pin
94stangfan16-Aug-04 12:22
Member94stangfan16-Aug-04 12:22 

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

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