Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProcessStartInfo run exe in PATH envirionment variable

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

like image 800
Marthijn Avatar asked Feb 02 '26 20:02

Marthijn


1 Answers

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);
like image 190
Oded Avatar answered Feb 04 '26 09:02

Oded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!