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

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Win32; //对注册表操作
    using System.Collections; //使用Arraylist
    using System.Security.Cryptography;//加密解密
    using System.IO;    //文件操作
    using System.Runtime.InteropServices;//调用DLL DllImport
    using System.Management;  //获取硬件信息
    using System.Net;       //获取IP地址是用到
    using System.Drawing;   //image
    using System.Net.NetworkInformation;    //ping 用到
    using System.Text.RegularExpressions;   //正则
    using System.Data;
    using System.Data.SqlClient;
    using Microsoft.VisualBasic;   //简体转繁体时用到
    using System.Web;       //html UrlEncode


    //注册表操作
        public class GF_RegReadWrite
        {
           
            /// <summary>
            /// 读取路径为keypath,键名为keyname的注册表键值,缺省返回def
            /// </summary>
            /// <param name="rootkey"></param>
            /// <param name="keypath">路径</param>
            /// <param name="keyname">键名</param>
            /// <param name="rtn">默认为null</param>
            /// <returns></returns>        
            static public bool GetRegVal(RegistryKey rootkey, string keypath, string keyname, out string rtn)
            {
                rtn = "";
                try
                {
                    RegistryKey key = rootkey.OpenSubKey(keypath);
                    rtn = key.GetValue(keyname).ToString();
                    key.Close();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
         
            /// <summary>
            /// 设置路径为keypath,键名为keyname的注册表键值为keyval
            /// </summary>
            /// <param name="rootkey"></param>
            /// <param name="keypath"></param>
            /// <param name="keyname"></param>
            /// <param name="keyval"></param>
            /// <returns></returns>
            static public bool SetRegVal(RegistryKey rootkey, string keypath, string keyname, string keyval)
            {
                try
                {
                    RegistryKey key = rootkey.OpenSubKey(keypath, true);
                    if (key == null)
                        key = rootkey.CreateSubKey(keypath);
                    key.SetValue(keyname, (object)keyval);
                    key.Close();
                    return true;
                }
                catch
                {
                    return false;
                }
            }

            /// 创建路径为keypath的键
            private RegistryKey CreateRegKey(RegistryKey rootkey, string keypath)
            {
                try
                {
                    return rootkey.CreateSubKey(keypath);
                }
                catch
                {
                    return null;
                }
            }
            /// 删除路径为keypath的子项
            private bool DelRegSubKey(RegistryKey rootkey, string keypath)
            {
                try
                {
                    rootkey.DeleteSubKey(keypath);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
            /// 删除路径为keypath的子项及其附属子项
            private bool DelRegSubKeyTree(RegistryKey rootkey, string keypath)
            {
                try
                {
                    rootkey.DeleteSubKeyTree(keypath);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
            /// 删除路径为keypath下键名为keyname的键值
            private bool DelRegKeyVal(RegistryKey rootkey, string keypath, string keyname)
            {
                try
                {
                    RegistryKey key = rootkey.OpenSubKey(keypath, true);
                    key.DeleteValue(keyname);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
  • 相关阅读:
    php图片上传代码
    数据库笔记
    数学函数类方法的使用.java
    有n人围成一圈,顺序排号。从第1个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来的第几号的那位。
    现有有N个学生的数据记录,每个记录包括学号、姓名、三科成绩。 编写一个函数input,用来输入一个学生的数据记录。 编写一个函数print,打印一个学生的数据记录。 在主函数调用这两个函数,读取N条记录输入,再按要求输出。 N<100
    求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一个数字
    分数相加减的代码(c++)
    Caesar cipher
    db2、Oracle存储过程引号用法
    CSS基础总结
  • 原文地址:https://www.cnblogs.com/kevinGao/p/2671035.html
Copyright © 2011-2022 走看看