C#注册表操作类-阿里云开发者社区

开发者社区> 开发与运维> 正文

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

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章