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

本文实例讲述了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;
}
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;
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值