C# 重启exe

时间:2023-12-19 12:11:32
休夸此地分天下
c# 关闭和重启.exe程序
Process[] myprocess = Process.GetProcessesByName("a");
if (myprocess.Count() > )//判断如果存在
{
//myprocess[0].Kill();//关闭程序
}
else
{
try
{
Process newProcess = new Process();//创建一个新的进程
ProcessStartInfo startInfo = new ProcessStartInfo();//启动进程时使用的集合
//startInfo.FileName = Environment.CurrentDirectory + "\\Release1\\a.exe";//要启动的应用程序
startInfo.FileName = "E:\\work\\Release\\a.exe";//要启动的应用程序
startInfo.WindowStyle = ProcessWindowStyle.Normal;//启动应用程序时使用的窗口状态
//startInfo.WorkingDirectory = Environment.CurrentDirectory + "\\Release1\\";//要启动应用程序的路径
newProcess.StartInfo = startInfo;//把启动进程的信息赋值给新建的进程
newProcess.StartInfo.UseShellExecute = false;//是否使用操作系统shell执行该程序
newProcess.Start();
}
catch
{
//退出控制台程序
Application.Exit();
}