Click here to Skip to main content
11,929,232 members (54,912 online)
Click here to Skip to main content
Add your own
alternative version


46 bookmarked

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

You may also be interested in...

Comments and Discussions

QuestionStart external process Pin
naveen ranjan21-Mar-14 23:10
membernaveen ranjan21-Mar-14 23:10 
QuestionProcess.Start() ... NOT STARTED ??? Pin
Ekvilibrium16-Jan-10 8:06
memberEkvilibrium16-Jan-10 8:06 
GeneralMy vote of 2 Pin
titwan3-Dec-08 6:12
membertitwan3-Dec-08 6:12 
Generaldoc 2 pdf Pin
Ali Ghazaei6-Oct-08 11:13
memberAli Ghazaei6-Oct-08 11:13 
GeneralShell to use PDF printer Pin
Ali Ghazaei28-Sep-08 14:06
memberAli Ghazaei28-Sep-08 14:06 
Questionhow to use parameter Pin
Member 372990228-Aug-08 21:06
memberMember 372990228-Aug-08 21:06 
GeneralDifferent article/good job Pin
Samuel Allen7-Jun-08 14:37
memberSamuel Allen7-Jun-08 14:37 
GeneralMy external App is not finishing Pin
liorjj20-Oct-07 23:22
memberliorjj20-Oct-07 23:22 
QuestionHow to start an application in foreground Pin
Abdul Hasib2-Jul-07 2:18
memberAbdul Hasib2-Jul-07 2:18 
AnswerRe: How to start an application in foreground Pin
nekropatolog26-Aug-07 22:36
membernekropatolog26-Aug-07 22:36 
QuestionProcess.Start("Notepad.exe") from Service. Pin
Kent Keller3-Apr-07 14:05
memberKent Keller3-Apr-07 14:05 
QuestionRe: Process.Start("Notepad.exe") from Service. Pin
auxcom25-May-08 16:14
memberauxcom25-May-08 16:14 
QuestionTo call a program Pin
alexTCT17-Oct-06 15:52
memberalexTCT17-Oct-06 15:52 
QuestionHow to use runas ? Pin
Redaemon20-Jan-06 7:24
memberRedaemon20-Jan-06 7:24 
Questionan funny problem Pin
mostafa.hk13-Jan-06 19:25
membermostafa.hk13-Jan-06 19:25 
QuestionWhat about starting a process as a different user? Pin
wyatt blake4-Oct-05 2:14
memberwyatt blake4-Oct-05 2:14 
GeneralBackground UI Pin
Zenlander30-Jun-05 21:34
memberZenlander30-Jun-05 21:34 
GeneralRe: Background UI Pin
ITGFanatic6-Mar-07 13:00
memberITGFanatic6-Mar-07 13:00 
GeneralRunning external application in .Net CF Pin
Vasil Zhekov13-Oct-04 5:16
sussVasil Zhekov13-Oct-04 5:16 
GeneralRe: Running external application in .Net CF Pin
CRoberto4-Feb-05 3:32
memberCRoberto4-Feb-05 3:32 
GeneralRunning the process inside the application Pin
Mesrop Simonian27-Feb-04 12:47
memberMesrop Simonian27-Feb-04 12:47 
GeneralAbsoute paths Pin
NameOfTheDragon11-Jun-03 1:38
memberNameOfTheDragon11-Jun-03 1:38 
GeneralRe: Absoute paths Pin
WillemSe11-Jun-03 7:58
memberWillemSe11-Jun-03 7:58 
GeneralRe: Absoute paths Pin
94stangfan16-Aug-04 13:22
member94stangfan16-Aug-04 13: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.

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