ProcessStartInfo run exe in PATH envirionment variable

2k Views Asked by At

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

2

There are 2 best solutions below

0
On

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.

1
On

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);