注册表的基本操作(.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

 

  

 

 

 

转载于:https://www.cnblogs.com/jingsha/p/5118865.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值