zoukankan      html  css  js  c++  java
  • 注册表的基本操作(.Net)

    在用C#进行Winform开发的时候,会涉及对注册表的操作。

    主要用到Registry、RegistryKey类,在Microsoft.Win32命名空间下。

    Regisgtry对象包含注册表常用5个键的管理,根据静态属性获得各键的RegistryKey对象,通过RegistryKey对象进行键值的增删查操作。

    Registry.ClassesRoot、Registry.CurrentUser、Registry.LocalMachine

    Registry.Users、Registry.CurrentConfig,分别对应如下5个键值

    RegisgtryKey类提供了增删改的静态方法。

    读信息,提供重载方式,增加权限的控制。Registry.LocalMachine.OpenSubKey()

    增信息,如果存在就是修改。Regisgtry.LocalMachine.CreateSubKey()

    删信息,在进行删除的时候如果键下面包含子键,需要逐层删除。Registry.LocalMachine.DeleteSubKey()

    递归删除注册表的方法 

     1 private void Delete(string regPath, RegistryKey reg)
     2         {
     3             if (reg.OpenSubKey(regPath) == null)
     4                 return;
     5             if (reg.OpenSubKey(regPath).GetSubKeyNames().Length > 0)
     6             {
     7 
     8                 foreach (string s in reg.OpenSubKey(regPath).GetSubKeyNames())
     9                 {
    10                     Delete(s, reg.OpenSubKey(regPath, true));
    11                 }
    12                 reg.DeleteSubKey(regPath);
    13             }
    14             else
    15             {
    16                 reg.DeleteSubKey(regPath);
    17             }
    18         }
    View Code

     

      

     

     

     

  • 相关阅读:
    The EF 6.x DbContextGenerator templates are not available for VS2010
    selenium定位tr及td,并获取其文本及属性
    selenium基本操作
    Git入门
    独热编码OneHotEncoder简介
    openCV中直方图均衡化算法的理解
    pyinstaller生成exe文件失败
    图像形态学运算
    对双边滤波的理解
    PyQt中对RadioButton分组
  • 原文地址:https://www.cnblogs.com/jingsha/p/5118865.html
Copyright © 2011-2022 走看看