本文实例讲述了C#实现读取注册表监控当前操作系统已安装软件变化的方法。分享给大家供大家参考。具体实现方法如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
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#程序设计有所帮助。