using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.IO; namespace Backup { class Program { static void Main(string[] args) { //如需要更新升级程序才可以打开 bool exists = CheckIsRun(); if (exists) { Console.WriteLine("正在关闭升级软件"); Thread.Sleep(2000); } exists = CheckIsRun(); if (exists) { Console.WriteLine("不能正常关闭升级软件"); return; } string appPath = Directory.GetParent(System.AppDomain.CurrentDomain.BaseDirectory).FullName + "\\"; string upPath = string.Format("{0}Upgrade.exe.up", appPath); string destPath = string.Format("{0}Upgrade.exe", appPath); if (File.Exists(upPath)) { File.Copy(upPath, destPath, true); } } public static bool CheckIsRun() { bool returnValue = false; try { Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName("upgrade"); foreach (Process process in processes) { if (process.Id != current.Id) { if (System.IO.Path.GetFileNameWithoutExtension(process.MainModule.FileName).ToLower() == "upgrade") { process.Kill(); returnValue = true; } } } } catch (Exception ex) { returnValue = false; } return returnValue; } } }