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); //调用自身来查找剩余子项
                }
            }
        }
    }
  • 相关阅读:
    LeetCode
    LeetCode
    控制反转(Ioc)
    KMP算法
    *&m与m的区别
    函数指针与函数指针数组的使用方法
    C++四种类型转换
    内存分配:堆内存,栈内存
    汇编 基础
    i++,++i 作为参数
  • 原文地址:https://www.cnblogs.com/qq1223558/p/3056613.html
Copyright © 2011-2022 走看看