private void ReStartWin(String path , String file)
{
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
//设置外部程序名
info.FileName = file;
//设置外部程序的工作目录为
info.WorkingDirectory = path;
//正常方式启动
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
//声明一个程序类
System.Diagnostics.Process Proc;
try
{
Proc = System.Diagnostics.Process.Start(info);
System.Threading.Thread.Sleep(500);
}
catch (System.ComponentModel.Win32Exception)
{
return;
}
}
private bool CloseProc(string ProcName)
{
bool result = false;
System.Collections.ArrayList procList = new System.Collections.ArrayList();
string tempName = "";
foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
{
tempName = thisProc.ProcessName;
procList.Add(tempName);
if (tempName == ProcName)
{
if (!thisProc.CloseMainWindow())
thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程
result = true;
}
}
return result;
}
上面的两个函数,一个用来启动其他程序,一个用来关闭其他程序。当你需要做软件升级功能的时候。就需要启动升级程序,升级自己,但是首先要关闭掉自己,再进行升级。升级完成后,还要再启动一下被升级的程序。
724




被折叠的 条评论
为什么被折叠?



