Files
RevokeMsgPatcher/RevokeMsgPatcher.MultiInstance/FormMultiInstance.cs

119 lines
3.8 KiB
C#
Raw Normal View History

2019-10-22 23:11:53 +08:00
using Microsoft.Win32;
using System;
2019-10-22 00:43:37 +08:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
2019-10-22 23:11:53 +08:00
using System.Diagnostics;
2019-10-22 00:43:37 +08:00
using System.Drawing;
2019-10-22 23:11:53 +08:00
using System.IO;
2019-10-22 00:43:37 +08:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RevokeMsgPatcher.MultiInstance
{
public partial class FormMultiInstance : Form
{
public FormMultiInstance()
{
InitializeComponent();
2019-10-22 23:11:53 +08:00
string installFolder = FindInstallPathFromRegistry("Wechat");
if (!string.IsNullOrEmpty(installFolder))
{
string wechatPath = Path.Combine(installFolder, "WeChat.exe");
if (File.Exists(wechatPath))
{
txtPath.Text = wechatPath;
}
}
}
private void btnChoosePath_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog
{
Multiselect = false,
Title = "请选择微信启动主程序",
Filter = "微信主程序|WeChat.exe"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
txtPath.Text = dialog.FileName;
}
}
private void btnStart_Click(object sender, EventArgs e)
{
if (File.Exists(txtPath.Text))
{
2019-12-14 21:18:27 +08:00
Process[] processes = Process.GetProcessesByName("WeChat");
ProcessUtil.CloseMutexHandle(processes);
2019-10-22 23:11:53 +08:00
// 启动多个实例
for (int i = 0; i < startNum.Value; i++)
{
2019-12-14 21:18:27 +08:00
//var t = new Task(() =>
//{
// Process newInstance = Process.Start(txtPath.Text);
// newInstance.WaitForInputIdle();
// ProcessUtil.CloseMutexHandle(newInstance);
//});
//t.Start();
Process newInstance = Process.Start(txtPath.Text);
//newInstance.WaitForInputIdle();
//ProcessUtil.CloseMutexHandle(newInstance);
2019-10-22 23:11:53 +08:00
}
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://github.com/huiyadanli/RevokeMsgPatcher");
}
/// <summary>
/// 从注册表中寻找安装路径
/// </summary>
/// <param name="uninstallKeyName">
/// 安装信息的注册表键名
/// 微信WeChat
/// QQ{052CFB79-9D62-42E3-8A15-DE66C2C97C3E}
/// TIMTIM
/// </param>
/// <returns>安装路径</returns>
public static string FindInstallPathFromRegistry(string uninstallKeyName)
{
try
{
RegistryKey key = Registry.LocalMachine.OpenSubKey($@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{uninstallKeyName}");
if (key == null)
{
return null;
}
object installLocation = key.GetValue("InstallLocation");
key.Close();
if (installLocation != null && !string.IsNullOrEmpty(installLocation.ToString()))
{
return installLocation.ToString();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return null;
2019-10-22 00:43:37 +08:00
}
2019-12-14 21:18:27 +08:00
private void button1_Click(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("WeChat");
ProcessUtil.CloseMutexHandle(processes);
}
private void mutexHandleCloseTimer_Tick(object sender, EventArgs e)
{
}
2019-10-22 00:43:37 +08:00
}
}