3

I'm trying to run an exe using ProcessStartInfo. The problem is I only want to specify the exe name, and add the executable path to the PATH environment variable in Windows. When I try to run my application I got a FileNotFoundException. Everything works fine when I start the process with the full name. Any ideas?

-- Edit: Thanks for the comments, Ill give an example to make it more clear:

ProcessStartInfo p = new ProcessStartInfo("example.exe");

I added the path of example.exe in the Windows Envirionment PATH variable manually, but still my application can't start the process example.exe

Marthijn
  • 3,292
  • 2
  • 31
  • 48

2 Answers2

3

You can use GetEnvironmentVariable and SetEnvironmentVariable that are on the Environment class.

var currentPathVariable = Environment.GetEnvironmentVariable("path");
var newPathVariable = currentPathVariable + ";another path";
Environment.SetEnvironmentVariable("path", newPathVariable);
Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

You could create a sub key in the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths in the registry.

Have a look at Registering Applications Using the App Paths sub key.

Norbert Willhelm
  • 2,579
  • 1
  • 23
  • 33