I generate a ProcessStartInfo by referencing a filename-only executable, without giving the absolute path. I expect the operating system to resolve the concrete location by using the PATH environment variable.
However, on some installations, the PATH variable is not set correctly and upon starting the Process by calling Process.Start()
it will throw a
System.ComponentModel.Win32Exception
The system cannot find the file specified
Are there programmatic options to check if the Process.Start will work beforehand?
I tried to use File.Exists(fileName)
, but this does only work for files located in the applications working directory.
In the command prompt you could use the following call to determine if it will work:
//example where a file is found
C:\>where calc.exe
C:\Windows\System32\calc.exe
//example where a file is not found
C:\>where foo.exe
INFO: Could not find files for the given pattern(s).
Is there something alike in .net to determine beforehand if the file path can be resolved so that Process.Start() will not throw?