C# 我的注册表操作类
using System;
using System.Collections.Generic;
using System.Text; using Microsoft.Win32;
using System.Collections; namespace War3Screen
{
/// <summary>
/// 注册表操作类--kongfl888 2013
///
/// </summary>
class RegOperator
{ /// <summary>
/// 获取某键下的某键值
/// </summary>
/// <param name="_registrykey">注册表基项如 Registry.CurrentUser</param>
/// <param name="mainKeystr">项的注册表键path</param>
/// <param name="name"></param>
/// <returns></returns>
public static string Getkey(RegistryKey _registrykey, string mainKeystr,string name)
{
string valueStr = string.Empty; try
{ RegistryKey regKey = _registrykey;
RegistryKey mainKey = regKey.OpenSubKey(mainKeystr); valueStr = mainKey.GetValue(name).ToString();
}
catch { }
return valueStr; } /// <summary>
/// 设置和修改某键值
/// </summary>
/// <param name="_registrykey">注册表基项如 Registry.CurrentUser</param>
/// <param name="mainKeystr">项的注册表键path</param>
/// <param name="name">项名</param>
/// <param name="valueStr">项值</param>
/// <returns></returns>
public static bool Setkey(RegistryKey _registrykey, string mainKeystr, string name, string valueStr)
{
bool sc = false;
try
{
RegistryKey regKey = _registrykey;
RegistryKey mainKey = regKey.OpenSubKey(mainKeystr, true);
mainKey.SetValue(name, valueStr, RegistryValueKind.DWord); sc = true;
}
catch { sc = false; }
return sc;
} /// <summary>
/// 新建子键
/// </summary>
/// <param name="regKey">注册表基项如 Registry.CurrentUser</param>
/// <param name="SubKeyPath">子键路径</param>
/// <param name="SubKey">子键名</param>
/// <param name="keyValue">子键值</param>
public static bool Createkey(RegistryKey regKey, string SubKeyPath, string SubKey, string valueName, string keyValue, RegistryValueKind valueKind)
{
try
{
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
//添加子键和值
RegistryKey subkey = optionKey.CreateSubKey(SubKey);
subkey.SetValue(valueName, keyValue, valueKind);
return true;
}
catch
{
return false;
throw;
} } /// <summary>
/// 重载Createkey
/// </summary>
/// <param name="regKey"></param>
/// <param name="SubKeyPath"></param>
/// <param name="SubKey"></param>
public static bool Createkey(RegistryKey regKey, string SubKeyPath, string SubKey)
{
try
{
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
optionKey.CreateSubKey(SubKey);
return true;
}
catch
{
return false;
throw; } } /// <summary>
/// 删除子键
/// </summary>
/// <param name="regKey">注册表基项如 Registry.CurrentUser</param>
/// <param name="SubKeyPath">子键路径</param>
/// <param name="SubKey">子键名</param>
public static bool DelKey(RegistryKey regKey, string SubKeyPath, string SubKey)
{
try
{
//打开注册表 RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true); string[] subKeys = optionKey.GetSubKeyNames(); foreach (string akey in subKeys)
{
if (akey == SubKey)
{
optionKey.DeleteSubKeyTree(SubKey);
return true;
}
}
return false; }
catch
{
return false;
throw;
}
} }
}
C# 我的注册表操作类的更多相关文章
- C#注册表操作类--完整优化版
using System; using System.Collections.Generic; using System.Text; using Microsoft.Win32; namespace ...
- C#注册表操作类(完整版) 整理完整
/// <summary> /// 注册表基项静态域 /// /// 主要包括: /// 1.Registry.ClassesRoot 对应于HKEY_CLASSES_ROOT主键 /// ...
- C#注册表操作类(完整版)
下面贴出自己用C#写的注册表操作类,欢迎大家拍砖! 1.注册表基项静态域 1 /// <summary> 2 /// 注册表基项静态域 3 /// 4 /// 主要包括: 5 /// 1. ...
- 注册表操作 Microsoft.Win32.Registry与RegistryKey类
一.注册表操作简介 Registry 类,RegistryKey 类提供了操作注册表的接口 RegistryValueKind:用于指定操作注册表的数据类型 一.注册表巢 在注册表中,最上面的节点是注 ...
- MFC学习 文件操作注册表操作
c读写文件 void CFileView::OnRead() { FILE *pFile = fopen("1.txt", "r"); /*char ch[10 ...
- delphi 注册表操作(读取、添加、删除、修改)完全手册
DELPHI VS PASCAL(87) 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...
- CRegKey 注册表操作
CRegKey 注册表操作 标签: accessnulluserpathbyteie 2011-11-03 13:55 3477人阅读 评论(0) 收藏 举报 分类: win32(7) 1.简介 ...
- Delphi的注册表操作
转帖:Delphi的注册表操作 2009-12-21 11:12:52 分类: Delphi的注册表操作 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创 ...
- 【读书笔记】C#高级编程 第二十四章 文件和注册表操作
(一)文件和注册表 对于文件系统操作,相关的类几乎都在System.IO名称空间中,而注册表操作由System.Win32名称空间中的类来处理. (二)管理文件系统 System.MarshalByR ...
随机推荐
- Team Foundation Server 2015使用教程--读取器tfs组的checkin权限修改
- Linux通过使用Sambaserver示例
Linux通过使用Sambaserver示例 实验环境: Vbox下一个.Rehat5虚拟机 使用sambaserver 目的:使用sambaserver将文件上传到server上 [root@rh5 ...
- 走向DBA[MSSQL篇] 从SQL语句的角度 提高数据库的访问性能
原文:走向DBA[MSSQL篇] 从SQL语句的角度 提高数据库的访问性能 最近公司来一个非常虎的dba 10几年的经验 这里就称之为蔡老师吧 在征得我们蔡老同意的前提下 我们来分享一下蔡老给我们 ...
- “采用VS2010至MFC4.2发育”最后溶液
我层2010年这方面的研究进行了简单(http://blog.csdn.net/boweirrking/article/details/5477062),那时候没有深入思考过这当中的原理,最终给出的方 ...
- MySQL 更新中国列:1366 Incorrect string value 问题解决了
周围环境:Win7 64位置,mysql-5.6.25-winx64,MySQL workbench 问题:MySQL在更新时出现异常: warning(s): 1366 Incorrect stri ...
- MVC中使用泛型仓储模式和依赖注入
在ASP.NET MVC中使用泛型仓储模式和依赖注入,实现增删查改 原文链接:http://www.codeproject.com/Articles/838097/CRUD-Operations-Us ...
- OR1200数据Cache运用情景分析
以下摘录<步骤吓得核心--软-core处理器的室内设计与分析>一本书 13.7DCache使用情景之中的一个--存储指令运行阶段DCache失靶 存储指令运行阶段DCache失靶这样的情景 ...
- JavaScript中null和undefined的总结
先说null,它表示一个特殊值,常用来描述“空值”.对null执行typeof运算,结果返回字符串“object”,也就是说,可以将null认为是一个特殊的对象值,含义是“非对象”(感觉怪怪的).实际 ...
- JavaScript总结一下--创建对象
在JavaScript象主要就是用下面三种语句: var box=new Object(); 或var box=Object(); var box={};//字面量 function Bo ...
- Android设计模式(五岁以下儿童)--简单工厂模式
1.面试的时候问这个问题: 在ListView 的item小程序.很多不同的显示风格.或者是,为了更好地维护,不同的样式,应该怎么做? 我一下就想到的是工厂的模式,利用project,编写ViewFa ...