zoukankan      html  css  js  c++  java
  • C#使用枚举方法来实现读取用户电脑中安装的软件

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Win32;
    namespace project
    {
        public class RegistryOperation
        {
            public static void Main(string[] args)
            {
                //定义顶级节点的路径
                RegistryKey ourkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\");
                //调用方法来枚举出该节点下的所有子项
                GetSubKeys(ourkey);
                //下面一句是让用户按下一个键后关闭程序
                Console.ReadKey(true);
            }
            /// <summary>
            /// 枚举出注册表某项下面的所有子项
            /// </summary>
            /// <param name="SubKey"></param>
            private static void GetSubKeys(RegistryKey SubKey)
            {
                foreach (string sub in SubKey.GetSubKeyNames())
                {
                    //string subKey = string.Format(SubKey + @"\" + sub);
                    //Console.Write(SubKey + @"\" + sub);
                    RegistryKey local = Registry.Users;
                    local = SubKey.OpenSubKey(sub, true);
                    Console.WriteLine(local.GetValue("DisplayName","未知"));    //读取出安装的软件名称,未读出的显示未知
                    GetSubKeys(local); //调用自身来查找剩余子项
                }
            }
        }
    }
  • 相关阅读:
    python 协程
    数据库中的一对多,多对多实例
    source命令
    HTTP 协议报文解析
    html中的body和head有什么区别??
    xml json
    内置函数bytes()
    MySQL中的日期和时间函数
    MySQL中的数值函数
    MySQL中的字符串函数
  • 原文地址:https://www.cnblogs.com/qq1223558/p/3056613.html
Copyright © 2011-2022 走看看