#region 通過當前代碼執行路徑向上找到相關exe,並根據processes.Length判斷是否已啟動 private bool CheckAndOpenExe(string exeName) { Process[] processes = Process.GetProcessesByName ...
#region 通過當前代碼執行路徑向上找到相關exe,並根據processes.Length判斷是否已啟動
private bool CheckAndOpenExe(string exeName)
{
Process[] processes = Process.GetProcessesByName(exeName);
if (processes.Length > 0)
{
return true;
}
else
{
return OpenExe();
}
}
private bool OpenExe()
{
Process pr = new Process();
try
{
pr.StartInfo.FileName = string.Format(@"{0}\..\LotteryPro\LotteryPro.exe", AssemblyDirectory);
pr.Start();
return true;
}
catch
{
return true;
}
finally
{
if (pr != null)
{
pr.Close();
}
}
}
public static string AssemblyDirectory
{
get
{
string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}//獲取當前代碼運行的目錄
#endregion