Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ProcessStartInfo在PATH环境变量中运行exe_C#_Filenotfoundexception_Processstartinfo - Fatal编程技术网

C# ProcessStartInfo在PATH环境变量中运行exe

C# ProcessStartInfo在PATH环境变量中运行exe,c#,filenotfoundexception,processstartinfo,C#,Filenotfoundexception,Processstartinfo,我正在尝试使用ProcessStartInfo运行exe。问题是我只想指定exe名称,并将可执行路径添加到Windows中的path环境变量中。当我尝试运行我的应用程序时,我得到了一个FileNotFoundException。当我用全名开始这个过程时,一切都很好。有什么想法吗 -- 编辑:谢谢你的评论,我举一个例子来说明: ProcessStartInfo p = new ProcessStartInfo("example.exe"); 我在Windows Environment path变

我正在尝试使用ProcessStartInfo运行exe。问题是我只想指定exe名称,并将可执行路径添加到Windows中的path环境变量中。当我尝试运行我的应用程序时,我得到了一个FileNotFoundException。当我用全名开始这个过程时,一切都很好。有什么想法吗

-- 编辑:谢谢你的评论,我举一个例子来说明:

ProcessStartInfo p = new ProcessStartInfo("example.exe");
我在Windows Environment path变量中手动添加了example.exe的路径,但我的应用程序仍然无法启动example.exe的进程,该进程可以使用并且位于类中


您可以在注册表中的注册表项HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Path中创建一个子项


查看。

是否要以编程方式将其添加到path环境变量中?更改环境变量后是否重新启动应用程序?注销并重新登录,以确保所有进程(包括VS、Explorer和VS宿主进程)都使用修改后的环境变量。谢谢Hans,问题已解决。我不知道我也必须关闭VS(事实上我今天重新启动了我的机器,它工作了)。谢谢,但这不是我的意思。我在问题中加了一个例子,使问题更加清楚。
var currentPathVariable = Environment.GetEnvironmentVariable("path");
var newPathVariable = currentPathVariable + ";another path";
Environment.SetEnvironmentVariable("path", newPathVariable);