C#注册表操作类

简介: C#注册表操作类 时间:2010-07-10 15:11:38 来源:网络 作者:未知 点击:526次 using System;using System.Collections.Generic;using System.

C#注册表操作类

时间:2010-07-10 15:11:38 来源:网络 作者:未知 点击:526次
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace Haode
{
    class Regedit
    {
        /// <summary>
        /// 读取指定名称的注册表的值
        /// </summary>
        /// <param name="name">注册表值</param>
        /// <returns></returns>
        private string GetRegistData(string name)
        {
            string registData;
            RegistryKey hkml = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey aimdir = software.OpenSubKey("China228.com", true);
            registData = aimdir.GetValue(name).ToString();
            return registData;
        }

        /// <summary>
        /// 注册表中写数据
        /// </summary>
        /// <param name="name">注册表</param>
        /// <param name="tovalue">值</param>
        private void WTRegedit(string name, string tovalue)
        {
            RegistryKey hklm = Registry.LocalMachine;
            RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
            RegistryKey aimdir = software.CreateSubKey("China228.com");
            aimdir.SetValue(name, tovalue);
        }

        /// <summary>
        /// .删除注册表中指定的注册表项
        /// </summary>
        /// <param name="name">注册表</param>
        private void DeleteRegist(string name)
        {
            string[] aimnames;
            RegistryKey hkml = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey aimdir = software.OpenSubKey("China228.com", true);
            aimnames = aimdir.GetSubKeyNames();
            foreach (string aimKey in aimnames)
            {
                if (aimKey == name)
                    aimdir.DeleteSubKeyTree(name);
            }
        }

        /// <summary>
        /// 判断指定注册表项是否存在
        /// </summary>
        /// <param name="name">注册表</param>
        /// <returns></returns>
        private bool IsRegeditExit(string name)
        {
            bool _exit = false;
            string[] subkeyNames;
            RegistryKey hkml = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey aimdir = software.OpenSubKey("China228.com", true);
            subkeyNames = aimdir.GetSubKeyNames();
            foreach (string keyName in subkeyNames)
            {
                if (keyName == name)
                {
                    _exit = true;
                    return _exit;
                }
            }
            return _exit;
        }

   }
}
 
本篇文章来源于:开发学院 http://edu.codepub.com   原文链接:http://edu.codepub.com/2010/0710/24136.php

相关文章
|
29天前
|
C#
C#学习相关系列之数据类型类的三大特性(二)
C#学习相关系列之数据类型类的三大特性(二)
|
1月前
|
C#
58.c#:directory类
58.c#:directory类
12 0
|
1月前
|
C#
57.c#:directorylnfo类
57.c#:directorylnfo类
12 0
|
1月前
|
监控 C#
55.c#:file类
55.c#:file类
14 1
|
1月前
|
算法 C#
54.c#:random类
54.c#:random类
12 1
|
1月前
|
C#
51.c#:string类的静态方法
51.c#:string类的静态方法
19 1
|
1月前
|
C#
27.c#关键字sealed修饰类
27.c#关键字sealed修饰类
12 0
|
3月前
|
Java C#
C# 面向对象编程解析:优势、类和对象、类成员详解
OOP代表面向对象编程。 过程式编程涉及编写执行数据操作的过程或方法,而面向对象编程涉及创建包含数据和方法的对象。 面向对象编程相对于过程式编程具有几个优势: OOP执行速度更快,更容易执行 OOP为程序提供了清晰的结构 OOP有助于保持C#代码DRY("不要重复自己"),并使代码更易于维护、修改和调试 OOP使得能够创建完全可重用的应用程序,编写更少的代码并减少开发时间 提示:"不要重复自己"(DRY)原则是有关减少代码重复的原则。应该提取出应用程序中常见的代码,并将其放置在单一位置并重复使用,而不是重复编写。
50 0
|
26天前
|
C#
深入C#中的String类
深入C#中的String类
7 0
|
29天前
|
C#
C#学习系列相关之多线程(二)----Thread类介绍
C#学习系列相关之多线程(二)----Thread类介绍