Skip to content

Commit

Permalink
修改C#注入器,禁止wx自动升级
Browse files Browse the repository at this point in the history
  • Loading branch information
zmrbak committed Dec 3, 2019
1 parent e25328b commit 2a025d7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
Binary file modified 部分编译内容/微信DLL注入器V1.0.4.exe
Binary file not shown.
25 changes: 16 additions & 9 deletions 配套代码/L000WeChatDllInjector/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

Expand All @@ -14,22 +16,27 @@ namespace L000WeChatDllInjector
/// </summary>
public partial class App : Application
{
static Mutex mutex;
protected override void OnStartup(StartupEventArgs e)
{
//只运行一个实例
//把已经启动的实例,全部结束
Process thisProcess = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(thisProcess.ProcessName);

foreach (Process item in processes)
mutex = new Mutex(true, "WeChatDllInjector", out bool isNewInstance);
if (isNewInstance != true)
{
if (item.Id != thisProcess.Id)
IntPtr intPtr = FindWindowW(null, "单实例应用程序");
if (intPtr != IntPtr.Zero)
{
item.Kill();
SetForegroundWindow(intPtr);
}
}

base.OnStartup(e);
Shutdown();
}
}

[DllImport("User32", CharSet = CharSet.Unicode)]
static extern IntPtr FindWindowW(String lpClassName, String lpWindowName);

[DllImport("User32", CharSet = CharSet.Unicode)]
static extern Boolean SetForegroundWindow(IntPtr hWnd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -26,7 +27,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.4.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand Down
15 changes: 6 additions & 9 deletions 配套代码/L000WeChatDllInjector/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,14 @@ private void Bt_WxRestart_Click(object sender, RoutedEventArgs e)
{
//如果当前系统中,微信在运行,则重启微信
String WxPath = "";
Process[] processes = Process.GetProcesses();
Process[] processes = Process.GetProcessesByName("WeChat");
foreach (Process process in processes)
{
if (process.ProcessName.ToLower() == "WeChat".ToLower())
if (WxPath == "")
{
if (WxPath == "")
{
WxPath = process.MainModule.FileName;
}
process.Kill();
WxPath = process.MainModule.FileName;
}
process.Kill();
}

//启动微信
Expand All @@ -283,7 +280,7 @@ private void Bt_WxRestart_Click(object sender, RoutedEventArgs e)
try
{
RegistryKey registryKey = Registry.CurrentUser;
RegistryKey software = registryKey.OpenSubKey("Software\\Tencent\\WeChat");
RegistryKey software = registryKey.OpenSubKey("Software\\Tencent\\WeChat",true);
object InstallPath = software.GetValue("InstallPath");
WxPath = InstallPath.ToString() + "\\WeChat.exe";

Expand All @@ -292,7 +289,7 @@ private void Bt_WxRestart_Click(object sender, RoutedEventArgs e)

registryKey.Close();
}
catch
catch(Exception ex)
{
WxPath = "";
}
Expand Down

0 comments on commit 2a025d7

Please sign in to comment.