2019-12-17 21:57:53 +08:00
|
|
|
|
using System;
|
2019-10-22 00:43:37 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-10-22 23:11:53 +08:00
|
|
|
|
using System.Diagnostics;
|
2019-10-22 00:43:37 +08:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace RevokeMsgPatcher.MultiInstance
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class FormMultiInstance : Form
|
|
|
|
|
|
{
|
|
|
|
|
|
public FormMultiInstance()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2020-01-05 01:47:15 +08:00
|
|
|
|
|
|
|
|
|
|
// 标题加上版本号
|
|
|
|
|
|
string currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
|
|
|
|
if (currentVersion.Length > 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentVersion = " v" + currentVersion.Substring(0, 3);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.Text += currentVersion;
|
2019-10-22 23:11:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-17 01:33:00 +08:00
|
|
|
|
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
2019-10-22 23:11:53 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
Process.Start("https://github.com/huiyadanli/RevokeMsgPatcher");
|
2019-10-22 23:11:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-17 01:33:00 +08:00
|
|
|
|
private void btnStartTimer_Click(object sender, EventArgs e)
|
2019-10-22 23:11:53 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
mutexHandleCloseTimer.Start();
|
2019-12-17 21:57:53 +08:00
|
|
|
|
btnStartTimer.Enabled = false;
|
|
|
|
|
|
btnStopTimer.Enabled = true;
|
2019-10-22 23:11:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-17 01:33:00 +08:00
|
|
|
|
private void btnStopTimer_Click(object sender, EventArgs e)
|
2019-10-22 23:11:53 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
mutexHandleCloseTimer.Stop();
|
2019-12-17 21:57:53 +08:00
|
|
|
|
btnStartTimer.Enabled = true;
|
|
|
|
|
|
btnStopTimer.Enabled = false;
|
2019-10-22 23:11:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-17 01:33:00 +08:00
|
|
|
|
private List<WechatProcess> wechatProcesses = new List<WechatProcess>();
|
|
|
|
|
|
|
|
|
|
|
|
private void mutexHandleCloseTimer_Tick(object sender, EventArgs e)
|
2019-10-22 23:11:53 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
Process[] processes = Process.GetProcessesByName("WeChat");
|
|
|
|
|
|
Console.WriteLine("WeChat进程数:" + processes.Length);
|
|
|
|
|
|
// 添加新进程
|
|
|
|
|
|
foreach (Process p in processes)
|
2019-10-22 23:11:53 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
int i = 0;
|
|
|
|
|
|
for (i = 0; i < wechatProcesses.Count; i++)
|
2019-10-22 23:11:53 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
WechatProcess wechatProcess = wechatProcesses[i];
|
|
|
|
|
|
if (wechatProcess.Proc.Id == p.Id)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-10-22 23:11:53 +08:00
|
|
|
|
}
|
2019-12-17 01:33:00 +08:00
|
|
|
|
if (i == wechatProcesses.Count)
|
2019-10-22 23:11:53 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
wechatProcesses.Add(new WechatProcess(p));
|
2019-10-22 23:11:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-12-17 01:33:00 +08:00
|
|
|
|
// 关闭所有存在互斥句柄的进程
|
|
|
|
|
|
int num = 0;
|
|
|
|
|
|
for (int i = wechatProcesses.Count - 1; i >= 0; i--)
|
2019-10-22 23:11:53 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
WechatProcess wechatProcess = wechatProcesses[i];
|
|
|
|
|
|
if (!wechatProcess.MutexClosed)
|
|
|
|
|
|
{
|
|
|
|
|
|
wechatProcess.MutexClosed = ProcessUtil.CloseMutexHandle(wechatProcess.Proc);
|
|
|
|
|
|
Console.WriteLine("进程:" + wechatProcess.Proc.Id + ",关闭互斥句柄:" + wechatProcess.MutexClosed);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wechatProcess.Proc.HasExited)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 移除不存在的线程
|
|
|
|
|
|
wechatProcesses.RemoveAt(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
num++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-10-22 23:11:53 +08:00
|
|
|
|
}
|
2019-12-17 21:57:53 +08:00
|
|
|
|
lblProcNum.Text = "当前微信数量:" + num.ToString();
|
2019-10-22 00:43:37 +08:00
|
|
|
|
}
|
2019-12-14 21:18:27 +08:00
|
|
|
|
|
2019-12-17 01:33:00 +08:00
|
|
|
|
private void btnKillAll_Click(object sender, EventArgs e)
|
2019-12-14 21:18:27 +08:00
|
|
|
|
{
|
|
|
|
|
|
Process[] processes = Process.GetProcessesByName("WeChat");
|
2019-12-17 01:33:00 +08:00
|
|
|
|
if (processes.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (Process p in processes)
|
|
|
|
|
|
{
|
|
|
|
|
|
p.Kill();
|
|
|
|
|
|
}
|
|
|
|
|
|
MessageBox.Show("已经关闭所有微信进程,共" + processes.Length + "个", "提示");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("当前无微信进程", "提示");
|
|
|
|
|
|
}
|
2019-12-14 21:18:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-17 01:33:00 +08:00
|
|
|
|
private void btnCloseAllMutex_Click(object sender, EventArgs e)
|
2019-12-14 21:18:27 +08:00
|
|
|
|
{
|
2019-12-17 01:33:00 +08:00
|
|
|
|
Process[] processes = Process.GetProcessesByName("WeChat");
|
|
|
|
|
|
ProcessUtil.CloseMutexHandle(processes);
|
2019-12-14 21:18:27 +08:00
|
|
|
|
}
|
2019-12-17 01:33:00 +08:00
|
|
|
|
|
2019-12-17 21:57:53 +08:00
|
|
|
|
private void lblHowToUse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
|
|
|
|
{
|
2020-01-05 01:47:15 +08:00
|
|
|
|
Process.Start("https://github.com/huiyadanli/RevokeMsgPatcher/tree/master/RevokeMsgPatcher.MultiInstance");
|
2019-12-17 21:57:53 +08:00
|
|
|
|
}
|
2019-12-17 01:33:00 +08:00
|
|
|
|
|
2019-12-17 21:57:53 +08:00
|
|
|
|
private void FormMultiInstance_FormClosed(object sender, FormClosedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
mutexHandleCloseTimer.Stop();
|
|
|
|
|
|
}
|
2019-10-22 00:43:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|