开发者

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜