捕获错误。修复找不到微信注册表路径时,程序闪退的问题

This commit is contained in:
huiyadanli 2019-08-01 23:02:28 +08:00
parent 22b8138283
commit 43ce6ecb96
3 changed files with 70 additions and 44 deletions

View File

@ -34,7 +34,9 @@
## :book:使用方法 ## :book:使用方法
**请以管理员身份运行本程序,由于修改了微信的 `WeChatWin.dll` 文件,杀毒软件可能会弹出警告,放行即可** **请以管理员身份运行本程序,由于修改了微信的 `WeChatWin.dll` 文件,杀毒软件可能会弹出警告,放行即可。**
启动时会自动从注册表中获取微信的安装路径,如果没找到,需要手动选择微信路径。
环境要求: 环境要求:

View File

@ -13,6 +13,8 @@ namespace RevokeMsgPatcher
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{
try
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
@ -51,8 +53,23 @@ namespace RevokeMsgPatcher
//退出 //退出
Application.Exit(); Application.Exit();
} }
#endif #endif
} }
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show((e.ExceptionObject as Exception).Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
} }

View File

@ -17,6 +17,8 @@ namespace RevokeMsgPatcher
public static string AutoFindInstallPath() public static string AutoFindInstallPath()
{ {
// 微信的注册表路径 // 微信的注册表路径
try
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\WeChat"); RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\WeChat");
object installLocation = key.GetValue("InstallLocation"); object installLocation = key.GetValue("InstallLocation");
key.Close(); key.Close();
@ -37,6 +39,11 @@ namespace RevokeMsgPatcher
{ {
return installLocation.ToString(); return installLocation.ToString();
} }
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
return null; return null;
} }