I want to run an exe file with c# but I can't use Process.Start()
because I don't know the exe file's location.
I didn't start to writing so I don't have any code for now.
I want to run an exe file with c# but I can't use Process.Start()
because I don't know the exe file's location.
I didn't start to writing so I don't have any code for now.
Use following :
string locateFile = "cmd.exe";
string environPath = Environment.GetEnvironmentVariable("Path");
string[] paths = environPath.Split(new char[] { ';' }).ToArray();
string filePath = "";
foreach (string path in paths)
{
string file = Directory.GetFiles(path, locateFile, SearchOption.TopDirectoryOnly).FirstOrDefault();
if (file != null)
{
filePath = file;
break;
}
}
if (filePath.Length > 0)
{
Console.WriteLine("File location : '{0}'", filePath);
}
else
{
Console.WriteLine("File not found");
}
Console.ReadLine();