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# 我的注册表操作类的更多相关文章

  1. C#注册表操作类--完整优化版

    using System; using System.Collections.Generic; using System.Text; using Microsoft.Win32; namespace ...

  2. C#注册表操作类(完整版) 整理完整

    /// <summary> /// 注册表基项静态域 /// /// 主要包括: /// 1.Registry.ClassesRoot 对应于HKEY_CLASSES_ROOT主键 /// ...

  3. C#注册表操作类(完整版)

    下面贴出自己用C#写的注册表操作类,欢迎大家拍砖! 1.注册表基项静态域 1 /// <summary> 2 /// 注册表基项静态域 3 /// 4 /// 主要包括: 5 /// 1. ...

  4. 注册表操作 Microsoft.Win32.Registry与RegistryKey类

    一.注册表操作简介 Registry 类,RegistryKey 类提供了操作注册表的接口 RegistryValueKind:用于指定操作注册表的数据类型 一.注册表巢 在注册表中,最上面的节点是注 ...

  5. MFC学习 文件操作注册表操作

    c读写文件 void CFileView::OnRead() { FILE *pFile = fopen("1.txt", "r"); /*char ch[10 ...

  6. delphi 注册表操作(读取、添加、删除、修改)完全手册

    DELPHI VS PASCAL(87)  32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...

  7. CRegKey 注册表操作

    CRegKey 注册表操作 标签: accessnulluserpathbyteie 2011-11-03 13:55 3477人阅读 评论(0) 收藏 举报  分类: win32(7)  1.简介 ...

  8. Delphi的注册表操作

    转帖:Delphi的注册表操作 2009-12-21 11:12:52 分类: Delphi的注册表操作 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息.     一.创 ...

  9. 【读书笔记】C#高级编程 第二十四章 文件和注册表操作

    (一)文件和注册表 对于文件系统操作,相关的类几乎都在System.IO名称空间中,而注册表操作由System.Win32名称空间中的类来处理. (二)管理文件系统 System.MarshalByR ...

随机推荐

  1. Visual Studio Team Services使用教程--默认团队权限说明

  2. 三种字符编码:ASCII、Unicode和UTF-8

    原文:三种字符编码:ASCII.Unicode和UTF-8 什么是字符编码? 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字 ...

  3. cocos2dx 制作单机麻将(二)

    cocos2dx 制作单机麻将(二) 打乱麻将顺序2 前面解说了怎样打乱初始给定的麻将牌堆, 另一种是打乱随意给定的麻将牌堆 //混乱扑克2 void RandAppointCardData(BYTE ...

  4. 远程访问mysql(转)

    GRANT ALL PRIVILEGES ON *.* TO '<username>'@'<remote addr or %(for all ip addr)>'IDENTIF ...

  5. php形式的内容被处理

    /** * 过滤HTML内容RETURN * * @param $string * @param bool $html * * @return array|string */ public stati ...

  6. DWR入门的例子(一个)

    DWR(Direct Web Remoting)是WEB远程调用框架.使用这种框架使AJAX发展至今已成为非常easy.使用DWR能client利用JavaScript直接调用服务端的Java方法并返 ...

  7. HDOJ--4821--String【弦hash】

    联系:http://acm.hdu.edu.cn/showproblem.php?pid=4821 题意:给一个字符串,选m个长度为l的子串组成新的串.要求这m个子串互不同样,问有多少种组合. 字符串 ...

  8. HTC T328W刷机包 仿三星S5 UI美化 精简 S5落下

    ROM介绍 1.三星移植TouchWiz接口; 2.三星增加S4壁纸和图标美化; 3.正确ROM呈流线型; 4.正确ROM优化; 5.完成ROOT权限; 6.短信支持来信息亮屏功能(在短信设置里设置) ...

  9. ABP展现层——Javascript函数库

    ABP展现层——Javascript函数库 点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之21.ABP展现层——Javascript函数库 ABP是“ASP.N ...

  10. 下载文档--Struts2中国的文件下载被显示为空间的问题

    下载文档--Struts2中国人似乎是空文件下载格问题 前言:近期公司项目中用到文件下载,依据底层,决定使用struts2的文件下载模式. 乱码大多数都攻克了,竟然出现中文文件下载时,中文文字显示为空 ...