In .NET, is there an equivalent of the "where" command that is present on Windows Vista and Windows 7 machines? I need to resolve the hard path to an executable that is defined in the system path at install time, and not everyone installs everything using the default installation path.
Currently I call the "where" command as an external process, but this only works on Vista and Windows 7 machines, this does not work on XP out of the box.
preguntado el 08 de noviembre de 11 a las 19:11
Bender the Greatest
You have to read the environment variable PATH and look for the presence of the application in each of the path and use that. That is how the Powershell cmdlet
get-command funciona también - http://technet.microsoft.com/en-us/library/dd347726.aspx
Note: If the reason for getting the path through
where is to use the path and call the executable, you need not do that since the executable is already in PATH and you need get the path and then use it explicitly.
You can use the System.IO.Directory.EnumerateFiles() method to search for files Here's an example
It returns an array of string containing the path(s).