public static PathString TryLocate(String ProgramName) { foreach (var Dir in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator)) { var p = Dir.AsPath() / ProgramName; if (File.Exists(p)) { return(ResolvePathFromSystem(p.FullPath)); } if (OperatingSystem == OperatingSystemType.Windows) { if (File.Exists(p + ".exe")) { return(ResolvePathFromSystem((p + ".exe").FullPath)); } else if (File.Exists(p + ".cmd")) { return(ResolvePathFromSystem((p + ".cmd").FullPath)); } else if (File.Exists(p + ".bat")) { return(ResolvePathFromSystem((p + ".bat").FullPath)); } } } return(null); }