ReadWeChatPathClass.cs 890 B

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