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 ...
随机推荐
- MEF初体验之六:导出和元素据
在导出声明这一节中解释了部件导出服务和值的基础知识.在某些情况下,出于多种原因,关联与导出相关的信息是有必要的.通常,它被用来解释一个指定的普通契约实现的能力.这对于允许导入约束满足它的导出,或者导入 ...
- Windows PHone 8 获取硬件信息
/// <summary> /// 获取系统信息 /// </summary> private string GetDeviceInfo() { StringBuilder s ...
- android JNI 简单demo(2)它JNI demo 写
android JNI 简单demo(2)它JNI demo 写 一.搭建Cygwin 环境:http://blog.csdn.net/androidolblog/article/details/25 ...
- mysql数据库的安装以及常见优化设置
原文请详见:http://www.ucai.cn/blogdetail/7036?mid=1&f=5 能够在线执行查看效果哦! 本文依据优才网课程整理,面向web开发人员,内容以有用为主,专业 ...
- svn常见错误汇总
comment中的换行.把换行去掉就可以了
- [程序安装包制作] Advanced Installer 备忘
原文:[程序安装包制作] Advanced Installer 备忘 Product Information - Product Details 这个重点是Product Version.讲这个之前, ...
- interview(转)
http://ifeve.com/ali-think-12/ http://ifeve.com/think-in-ali-10/
- Sort函数的相关知识
sort与stable_sort 需包含头文件:#include <algorithm>因为它是库函数 这两个函数的原理都是快速排序,时间复杂度在所有排序中最低,为O(nlog2n) ...
- Android apk file
apk file 事实上zip文件. 您可以使用unzip命令提取. unzip example1.apk -d ./example_dir tree . ├── AndroidManifest.xm ...
- JBPM——MyEclipse开发环境的搭建
第一次接触JBPM我不知道如何在工程中的应用.查了一些资料.大约在JBPM随着时代的发展有一定的了解.首先JBPM它是JBoss件平台的一个组成部分.是一个灵活的,易扩展的工作流管理系统,仅仅只是这个 ...