关于QQ判断是否安装360 不需要扫描硬盘

来源:互联网 发布:傻瓜网站制作软件 编辑:程序博客网 时间:2024/05/16 14:24

 

前段时间关于QQ和360发生争执的事,很多用户说:“如果QQ不扫描硬盘,怎么知道我安装了360!”

嘿,话还真的不能说的这么绝对,判断系统中是否安装了某些软件,只需读取注册表中的值就行了。。。。。。

下面是我用C#写的,使用枚举来读取用户电脑中所有安装的软件名称:

Code:
  1. using System;   
  2. using System.Collections.Generic;   
  3. using System.Text;   
  4. using Microsoft.Win32;   
  5.   
  6. namespace project   
  7. {   
  8.     public class RegistryOperation   
  9.     {   
  10.         public static void Main(string[] args)   
  11.         {   
  12.             //定义顶级节点的路径   
  13.             RegistryKey ourkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/");   
  14.   
  15.             //调用方法来枚举出该节点下的所有子项   
  16.             GetSubKeys(ourkey);   
  17.   
  18.             //下面一句是让用户按下一个键后关闭程序   
  19.             Console.ReadKey(true);   
  20.         }   
  21.   
  22.         /// <summary>   
  23.         /// 枚举出注册表某项下面的所有子项   
  24.         /// </summary>   
  25.         /// <param name="SubKey"></param>   
  26.         private static void GetSubKeys(RegistryKey SubKey)   
  27.         {   
  28.             foreach (string sub in SubKey.GetSubKeyNames())   
  29.             {   
  30.                 RegistryKey local = Registry.Users;   
  31.                 local = SubKey.OpenSubKey(sub, true);   
  32.                 Console.WriteLine(local.GetValue("DisplayName","未知"));    //读取出安装的软件名称,未读出的显示未知   
  33.                 GetSubKeys(local); //调用自身来查找剩余子项   
  34.   
  35.             }   
  36.         }   
  37.   
  38.     }   
  39. }   

程序的运行结果,如下图所示:

是不是把所有安装的软件都显示出来了,呵呵。。。

原创粉丝点击