一个注册表操作类,很有用!
using System;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
using Microsoft.Win32;
namespace modify
{
/// <summary>
/// regedit 的摘要说明。
/// </summary>
public class regedit
{
public regedit()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 设置注册表值
/// </summary>
/// <param name="RegPath"></param>
/// <param name="valuename"></param>
/// <param name="keyvalue"></param>
/// <returns></returns>
public bool SetValue(string RegPath,string valuename,object keyvalue)
{
RegistryKey root=null;//基本的主键
string sub_path="";//获取除了基本的主键字符窜的子字符窜
if(RegPath.Length>=17&&RegPath.Substring(0,17)=="HKEY_CLASSES_ROOT")
{
root=Microsoft.Win32.Registry.ClassesRoot;//
sub_path=RegPath.Substring(17).Substring(1);//获取子字符串,前面去掉“\”
}
else if(RegPath.Length>=17&&RegPath.Substring(0,17)=="HKEY_CURRENT_USER")
{
root=Microsoft.Win32.Registry.CurrentUser;
sub_path=RegPath.Substring(17).Substring(1);
}
else if(RegPath.Length>=18&&RegPath.Substring(0,18)=="HKEY_LOCAL_MACHINE")
{
root=Microsoft.Win32.Registry.LocalMachine;
sub_path=RegPath.Substring(18).Substring(1);
}
else if(RegPath.Length>=10&&RegPath.Substring(0,10)=="HKEY_USERS")
{
root=Microsoft.Win32.Registry.Users;
sub_path=RegPath.Substring(10).Substring(1);
}
else if(RegPath.Length>=19&&RegPath.Substring(0,19)=="HKEY_CURRENT_CONFIG")
{
root=Microsoft.Win32.Registry.CurrentConfig;
sub_path=RegPath.Substring(19).Substring(1);
}
else
{
return false;
}
RegistryKey fatherkey = root;
string [] substringArray=sub_path.Split(new char[]{});
for(int i=0;i<substringArray.Length;i++)
{
RegistryKey thissubkey = fatherkey.OpenSubKey(substringArray[i],true);
if(thissubkey==null)
{
return false;
}
else
{
fatherkey = thissubkey;
}
}
fatherkey.SetValue(valuename,keyvalue);
return true;
}
/// <summary>
/// 得到注册表值
/// </summary>
/// <param name="RegPath"></param>
/// <param name="valueName"></param>
/// <returns></returns>
public object GetValue(string RegPath,string valueName)
{
RegistryKey root=null;//基本的主键
string sub_path="";//获取除了基本的主键字符窜的子字符窜
object result= null;
if(RegPath.Length>=17&&RegPath.Substring(0,17)=="HKEY_CLASSES_ROOT")
{
root=Microsoft.Win32.Registry.ClassesRoot;//
sub_path=RegPath.Substring(17).Substring(1);//获取子字符串,前面去掉“\”
}
else if(RegPath.Length>=17&&RegPath.Substring(0,17)=="HKEY_CURRENT_USER")
{
root=Microsoft.Win32.Registry.CurrentUser;
sub_path=RegPath.Substring(17).Substring(1);
}
else if(RegPath.Length>=18&&RegPath.Substring(0,18)=="HKEY_LOCAL_MACHINE")
{
root=Microsoft.Win32.Registry.LocalMachine;
sub_path=RegPath.Substring(18).Substring(1);
}
else if(RegPath.Length>=10&&RegPath.Substring(0,10)=="HKEY_USERS")
{
root=Microsoft.Win32.Registry.Users;
sub_path=RegPath.Substring(10).Substring(1);
}
else if(RegPath.Length>=19&&RegPath.Substring(0,19)=="HKEY_CURRENT_CONFIG")
{
root=Microsoft.Win32.Registry.CurrentConfig;
sub_path=RegPath.Substring(19).Substring(1);
}
else
{
root=null;
return("no root");
}
RegistryKey fatherkey = root;
string [] substringArray=sub_path.Split(new char[]{});
for(int i=0;i<substringArray.Length;i++)
{
RegistryKey thissubkey = fatherkey.OpenSubKey(substringArray[i]);
if(thissubkey==null)
{
return ("["+substringArray[i] +"] is not found");
}
else
{
fatherkey = thissubkey;
}
}
result=fatherkey.GetValue(valueName);
if(result==null)
{
return ("no value");
}
else
{
return result;
}
}
}
}
一个注册表操作类,很有用!相关推荐
- 用C#写的一个注册表操作类
该类实现了注册表读取.写入.删除.查找等功能. 实现代码: using System; using System.Collections.Generic; using System.Linq; usi ...
- RegistryCallback routine(CmRegisterCallback 注册表操作监控介绍)
RegistryCallback routine 过滤器驱动程序的常规RegistryCallback可以监视,阻止或修改一个注册表操作. 句法 C ++ NTSTATUS CmRegisterCal ...
- Delphi 注册表操作
Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操作注册表,要创建一个TRegistry对象:ARe ...
- delphi 注册表操作(读取、添加、删除、修改)完全手册
32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操作注册表,要创建一个TRegistry对象: ...
- delphi 注册表操作之(读取、添加、删除、修改)
32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操作注册表,要创建一个TRegistry对象: ...
- window注册表操作手册
环境: window 10企业版 .netcore 3.1 vs 2019 16.4.5 控制台程序以管理员身份运行 参照: Windows注册表内容详解 C#操作注册表 一.window注册表简介 ...
- 注册表操作(VC_Win32)
注册表操作(VC_Win32) 数据类型 注册表的数据类型主要有以下四种: 显示类型(在编辑器中) 数据类型 说明 REG_SZ 字符串 文本字符串 REG_MULTI_SZ ...
- 使用php创建一个注册表单,如何实现一个简单的注册表单
创建一个注册表单是非常容易的 - 它事实上意味着,你只需要创建一个表单,表单将更新一些User的模型对象(这个例子是一个Doctrine实体)并保存它. 受欢迎的FOSUserBundle 提供了一个 ...
- 注册表操作C/C++(实战实现程序自启动)
C/C++ 注册表操作 注册表概述 一.注册表数据结构 二.相关函数 1.创建键 RegCreateKeyEx() 2.关闭键RegCloseKey() 3.关闭键RegOpenKeyEx() 4.修 ...
- ObjectType HOOK干涉注册表操作(bypass Icesword,gmer,NIAP,etc.)
2011-04-19 15:41:58| 分类: Windows内核|字号 订阅 http://www.xfocus.net/articles/200802/966.html 创建时间:2008-0 ...
最新文章
- 精彩碰撞!神经网络和传统滤波竟有这火花?
- Image Super-Resolution Using Deep Convolutional Networks
- 微软(北京).NET俱乐部 2008雪上激情之旅-续
- 《Nature》上给青年科研工作者的几条忠告 (转载)
- 分析uboot中 make xxx_config过程
- Centos7.5 lnmp+mongodb扩展
- vs用c语言写贪吃蛇,熬书几个月,终于编出简易的贪吃蛇了,VS2013
- 近15亿元融资,够不够匹克“翻身”?
- [原创]软件测试工具简介及下载地址(不定时更新)
- SCO UNIX环境下自动增加网关的两种方法
- centos将某一目录权限给用户_CenTOS7使用ACL控制目录权限,只给某个用户访问特定目录...
- python2.7初学(〇)
- Easy-rules使用介绍
- 金山词霸怎样才能在PDF阅读器(ADOBE 7.0/9.0)上取词翻译
- RS232和RS485的协议原理及应用
- lin接口 连接计算机,db9接口(lin接口db9定义)
- 服务器ssd内存性能对比,真是大快人心 九款240/256G SSD大横评
- Spring 中 MongDB Conver转换器的使用
- 使用纯JavaCV实现颜色分割 / 轮廓提取 / 离焦 / 线性旋转变焦模糊 / 灰度化 / 标注等处理
- 海尔轰天雷t7linux转windowxp,XP改win7系统雨林木风详细教程