递归搜索注册表的例子

递归搜索注册表的例子

  1. using System;
  2. using Microsoft.Win32;
  3. namespace CleanRegistry
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             RegistryKey[] MyRootKeys = new RegistryKey[5];
  10.             MyRootKeys[0] = Registry.CurrentUser;
  11.             MyRootKeys[1] = Registry.ClassesRoot;
  12.             MyRootKeys[2] = Registry.LocalMachine;
  13.             MyRootKeys[3] = Registry.Users;
  14.             MyRootKeys[4] = Registry.CurrentConfig;
  15.             foreach (RegistryKey MyRootKey in MyRootKeys)
  16.             {
  17.                 FindSymantec( MyRootKey );
  18.             }
  19.         }
  20.         static void FindSymantec(RegistryKey MyKey)
  21.         {
  22.             //Console.WriteLine("Searching { 0 }...", MyKey.ToString());
  23.             // 获取所有键名
  24.             foreach (string MyValueName in MyKey.GetValueNames())
  25.             {
  26.                 // 键类型
  27.                 if( MyKey.GetValueKind(MyValueName) == RegistryValueKind.String )
  28.                 {
  29.                     // 获取键值
  30.                     string MyValue = MyKey.GetValue(MyValueName).ToString().ToLower();
  31.                     if ( MyValue.Contains("symantec antivirus") )
  32.                     {
  33.                         Console.WriteLine("{ 0 }/t{ 1 }/t{ 2 }", MyKey, MyValueName, MyValue);
  34.                     }
  35.                 }
  36.             }
  37.             // 获取所有子键,递归
  38.             if (MyKey.SubKeyCount != 0)
  39.             {
  40.                 // 获取子键名
  41.                 foreach (string MySubKey in MyKey.GetSubKeyNames())
  42.                 {
  43.                     // 打开子键
  44.                     RegistryKey SubKey;
  45.                     try
  46.                     {
  47.                         SubKey = MyKey.OpenSubKey(MySubKey);
  48.                     }
  49.                     catch
  50.                     {
  51.                         continue;
  52.                     }
  53.                     // 递归
  54.                     FindSymantec(SubKey);
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值