[英]How can I run an exe file with c# (I can't use Process.Start() because I don't know the exe file's location)
我想用 c# 運行一個 exe 文件,但我不能使用Process.Start()
因為我不知道 exe 文件的位置。
我還沒有開始寫,所以我現在沒有任何代碼。
使用以下:
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.