好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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#程序设计有所帮助。

dy("nrwz");

查看更多关于C#实现读取注册表监控当前操作系统已安装软件变化的方法的详细内容...

  阅读:131次