• C#注册表操作


    1、提供的函数类

         在C#中提供了Registry类、RegistryKey类来实现对注册表的操作。其中Registry类封装了注册表的七个基本主健:

          Registry.ClassesRoot 对应于HKEY_CLASSES_ROOT主键
      Registry.CurrentUser 对应于HKEY_CURRENT_USER主键
      Registry.LocalMachine 对应于 HKEY_LOCAL_MACHINE主键
      Registry.User 对应于 HKEY_USER主键
      Registry.CurrentConfig 对应于HEKY_CURRENT_CONFIG主键
      Registry.DynDa 对应于HKEY_DYN_DATA主键
      Registry.PerformanceData 对应于HKEY_PERFORMANCE_DATA主键

    RegistryKey类封装了对注册表的基本操作,包括读取,写入,删除。其中读取的主要函数有:

    OpenSubKey ( string name )方法主要是打开指定的子键。
      GetSubKeyNames ( )方法是获得主键下面的所有子键的名称,它的返回值是一个字符串数组。
      GetValueNames ( )方法是获得当前子键中的所有的键名称,它的返回值也是一个字符串数组。
      GetValue ( string name )方法是指定键的键值。

    写入的函数有:

    CreateSubKeystring name)方法是增加一个子键

    SetValuestring name,string value)方法是设置一个键的键值

    删除的函数:

    DeleteSubKey ( )方法:删除一个指定的子键。

    DeleteSubKeyTree ( )方法:

    此方法是彻底删除指定的子键目录,即:删除该子键以及该子键以下的全部子键。

    2、操作示例

    写:  
      RegistryKey   rkey   =   Registry.LocalMachine;  
      //The   second   parameter   tells   it   to   open   the   key   as   writable   
      RegistryKey rkey1   =   rkey.OpenSubKey("Software",true);  
      RegistryKey   rkey2   =   rkey1.CreateSubKey("Test");  
      rkey2.SetValue("Name",value);  
      rkey2.Close();  
      rkey1.Close();  
      读:  
      RegistryKey   rkey   =   Registry.LocalMachine;  
      //The   second   parameter   tells   it   to   open   the   key   as   writable  
      RegistryKey rkey1   =   rkey.OpenSubKey("Software\\Test",true);   
      value=rkey1.GetValue("Name");

  • 相关阅读:
    Hadoop集群(第3期)_VSFTP安装配置
    Hadoop集群(第5期)_Hadoop安装配置
    Hadoop集群(第6期)_WordCount运行详解
    Hadoop集群(第8期)_HDFS初探之旅
    Hadoop集群(第10期)_MySQL关系数据库
    Hadoop集群(第5期副刊)_JDK和SSH无密码配置
    Hadoop集群(第4期)_SecureCRT使用
    Hadoop集群(第9期)_MapReduce初级案例
    [winform]Value Object property expects either null/nothing value or int type
    【Winform】单元格的Formatted值的类型错误
  • 原文地址:https://www.cnblogs.com/jyz/p/1282708.html
Copyright © 2020-2023  润新知