zoukankan      html  css  js  c++  java
  • c# 操作注册表保存客户本地信息

    注册表帮助类

    internal sealed class RegistryHelper
        {
            private static string softwareKey = @"SoftwareDeepLandOrderWater";
    
            /// <summary>
            /// Gets the value by registry key. If the key does not exist, return empty string.
            /// </summary>
            /// <param name="key">registry key</param>
            /// <returns>Returns the value of the specified key.</returns>
            public static string GetValue(string key)
            {
                const string parameter = "key";
                if (null == key)
                {
                    throw new ArgumentNullException(parameter);
                }
    
                string strRet = string.Empty;
                try
                {
                    RegistryKey regKey = Registry.CurrentUser.OpenSubKey(softwareKey);
                    strRet = regKey.GetValue(key).ToString();
                }
                catch
                {
                    strRet = "";
                }
                return strRet;
            }
    
            /// <summary>
            /// Saves the key and the value to registry.
            /// </summary>
            /// <param name="key">registry key</param>
            /// <param name="value">the value of the key</param>
            /// <returns>Returns true if successful, otherwise return false.</returns>
            public static bool SaveValue(string key, string value)
            {
                const string parameter1 = "key";
                const string parameter2 = "value";
                if (null == key)
                {
                    throw new ArgumentNullException(parameter1);
                }
    
                if (null == value)
                {
                    throw new ArgumentNullException(parameter2);
                }
    
                bool bReturn = false;
                RegistryKey reg;
                reg = Registry.CurrentUser.OpenSubKey(softwareKey, true);
    
                if (null == reg)
                {
                    reg = Registry.CurrentUser.CreateSubKey(softwareKey);
                }
                reg.SetValue(key, value);
    
                return bReturn;
            }
        }
  • 相关阅读:
    MySQL之视图
    C# 学习笔记(二) 时间格式化字符串
    C# 学习笔记(一) Winform利用Assembly反射动态创建窗体
    puppet 4.4 System Requirements
    Linux下MySql启动时报错
    Linux Iptables
    Nginx Configure时配置
    Wireshark 使用教程
    Linux 下安装oracle数据库
    CaseFile
  • 原文地址:https://www.cnblogs.com/shuaimeng/p/14827960.html
Copyright © 2011-2022 走看看