C#实现读取注册表监控当前操作系统已安装软件变化的方法


本文实例讲述了C#实现读取注册表监控当前操作系统已安装软件变化的方法。分享给大家供大家参考。具体实现方法如下:

private static HybridDictionary GetSoftName()
{
 string strSoftName = string.Empty;
 HybridDictionary hdSoftName = new HybridDictionary();
 /*对注册表节点"Software/Microsoft/Windows/CurrentVersion/Uninstall"下的内容进行操作。
 RegistryKey Registry 为注册表操作类*/
 using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", false))
 {
  if (key != null)
  {
   foreach (string keyName in key.GetSubKeyNames())
   {
    using (RegistryKey key2 = key.OpenSubKey(keyName, false))
    {
     if (key2 != null)
     {
      string softwareName = Convert.ToString(key2.GetValue("DisplayName"));//获取DisplayName,如存在值,则系统中安装有该软件
      //string installLocation = key2.GetValue("InstallLocation", "").ToString();//软件安装路径
      if (!string.IsNullOrEmpty(softwareName))
      {
       if (!hdSoftName.Contains(softwareName))
       {
        hdSoftName.Add(softwareName, string.Empty);//将软件名作为集合的key
       }
      }
     }
    }
   }
  }
 }
 return hdSoftName;
}

希望本文所述对大家的C#程序设计有所帮助。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3