You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.9 KiB

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;
}
}
}