Running a process and the environment path variable

C

Clive Dixon

If I do

System.Diagnostics.Process p = new System.Diagnostics.Process;

p.StartInfo.FileName = "<an executable name>";

// ... (set other properties)

p.Start();

How can I force .NET to look for the named executable in the path? It does
not appear to do this by default.
 
G

Guest

By default it ignores the environment variable Path. You need to pad it while
you pass a file name.

e.g.
myProcess.Start(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "MyUtility.exe")

Optionally you can set WorkingDirectory on StartInfo (which is an instance
of ProcessStartInfo).
 
G

Guest

What I am doing with the product we're developing is to define an environment
variable e.g. set MyRoot=C:\MyProduct and then (because all the executables
are in the bin directory I use "%MyRoot%\bin\whatever.exe" and when I set
the Process I pass the name through
System.Environment.ExpandEnvironmentVariables()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top