110,567
社区成员
发帖
与我相关
我的任务
分享
Process _this = System.Diagnostics.Process.GetCurrentProcess();//这个变量保存本程序的进程信息 保存为全局变量
System.Diagnostics.Process[] processOnComputer = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process p in processOnComputer)
{
if (p.MainWindowHandle != IntPtr.Zero && p.MainWindowTitle != "")//只检测有窗口的程序
{
try
{
if(_this.Id != p.Id && p.MainModule.FileName == _this.MainModule.FileName)//如果不是本进程
{
p.Kill();//干掉后启动的本程序
p.Close();
p.Dispose();
//这里写你自己的程序 把自己从托盘显示出来
}
}
catch (Exception ex)
{
}
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
if (showF)
{
this.Visible = true; showF = false;
}
else { this.Visible = false; this.notifyIcon1.Visible = true; showF = true; }
}