c# 关闭和重启.exe程序

Process[] myprocess = Process.GetProcessesByName("a");
if (myprocess.Count() > 0)//判断如果存在
{
//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();
}

发布了144 篇原创文章 · 获赞 43 · 访问量 132万+

猜你喜欢

转载自blog.csdn.net/qq_25889465/article/details/103658589