zoukankan      html  css  js  c++  java
  • C#注册表操作类

    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

  • 相关阅读:
    model.object对象查询过滤、增删改、Q
    模板中的标签、过滤器
    模板(template)包含与继承
    url用法
    AD用户登录验证,遍历OU(LDAP)
    Python下操作sqlite3
    多线程应用-类(thread)
    数组(list)分组、分段
    多线程应用-函数方式(thread)
    IntelliJ IDEA maven项目 ***
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2032748.html
Copyright © 2011-2022 走看看