Reputation: 3402
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
Upvotes: 3
Views: 2122
Reputation: 2609
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.
Upvotes: 0
Reputation: 499382
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);
Upvotes: 3