• C# 操作注册表


    using System;
    using Microsoft.Win32;
    
    namespace TunEc.ZHJF.Common
    {
        public class OperateReg
        {
            /// <summary>
            /// 读取指定名称的注册表的值
            /// </summary>
            /// <param name="name">注册表值</param>
            /// <returns></returns>
            public static string GetRegData(string strItemName)
            {
                try
                {
                    string registData;
                    RegistryKey hkml = Registry.LocalMachine;
                    RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
                    RegistryKey zhjf = software.CreateSubKey("ZHJF");
                    // RegistryKey zhjf = software.OpenSubKey("ZHJF", true);
                    registData = zhjf.GetValue(strItemName.ToLower()).ToString();
                    return registData;
                }
                catch (Exception ex)
                {
                    MessageboxX.ShowError(ex.Message);
                    return "";
                }
            }
    
            /// <summary>
            /// 注册表中写数据 
            /// </summary>
            /// <param name="name">注册表</param>
            /// <param name="tovalue">值</param>
            public static void WriteReg(string strItemName, string strItemValue)
            {
                try
                {
                    RegistryKey hklm = Registry.LocalMachine;
                    RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
                    RegistryKey zhjf = software.CreateSubKey("ZHJF");
                    zhjf.SetValue(strItemName.ToLower(), strItemValue);
                }
                catch (Exception ex)
                {
                    MessageboxX.ShowError(ex.Message);
                }
            }
    
            /// <summary>
            /// .删除注册表中指定的注册表项
            /// </summary>
            /// <param name="name">注册表</param>
            public static void DeleteRegItem(string strItemName)
            {
                try
                {
                    RegistryKey hkml = Registry.LocalMachine;
                    RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
                    RegistryKey zhjf = software.CreateSubKey("ZHJF");
                    zhjf.DeleteValue(strItemName.ToLower());
                }
                catch (Exception ex)
                {
                    MessageboxX.ShowError(ex.Message);
                }
            }
    
            /// <summary>
            /// 判断指定注册表项是否存在
            /// </summary>
            /// <param name="name">注册表</param>
            /// <returns></returns>
            public static bool IsRegExit(string strItemName)
            {
                try
                {
                    bool _exit = false;
                    string[] subkeyNames;
                    RegistryKey hkml = Registry.LocalMachine;
                    RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
                    RegistryKey zhjf = software.CreateSubKey("ZHJF");
                    // RegistryKey zhjf = software.OpenSubKey("ZHJF", true);
                    subkeyNames = zhjf.GetValueNames();
                    foreach (string keyName in subkeyNames)
                    {
                        if (keyName.ToLower() == strItemName.ToLower())
                        {
                            _exit = true;
                            return _exit;
                        }
                    }
                    return _exit;
                }
                catch (Exception ex)
                {
                    MessageboxX.ShowError(ex.Message);
                    return false;
                }
            }
    
        }
    }
    
  • 相关阅读:
    板子们~缓慢更新
    Hello World!
    [SHOI2008]堵塞的交通traffic
    [JSOI2008]最大数
    [SCOI2005]扫雷
    [HAOI2007]上升序列
    [HAOI2007]理想的正方形
    [SCOI2003]字符串折叠
    [HAOI2008]移动玩具
    [BJOI2006]狼抓兔子
  • 原文地址:https://www.cnblogs.com/yannis/p/2041343.html
Copyright © 2020-2023  润新知