ReadWeChatPathClass.cs 982 B

123456789101112131415161718192021222324252627282930313233
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Security.AccessControl;
  4. public static class ReadWeChatPathClass
  5. {
  6. /// <summary>
  7. /// 读取微信路径
  8. /// </summary>
  9. /// <returns></returns>
  10. public static string ReadWeChatPath()
  11. {
  12. // 定义要读取的注册表路径
  13. string registryPath = @"SOFTWARE\Tencent\WeChat";
  14. string result = "";
  15. // 打开注册表项
  16. using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryPath,
  17. RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl))
  18. {
  19. if (key != null)
  20. {
  21. // 读取指定的键值
  22. object value = key.GetValue("InstallPath");
  23. if (value != null)
  24. {
  25. result = value.ToString();
  26. }
  27. }
  28. }
  29. return result + "\\WeChat.exe";
  30. }
  31. }