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

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Win32;
    
    namespace AirPatientForm
    {
        class RegistryDAO
        {
            public static string GetRegistData(string name)
            {
                if (!IsRegeditExit(name))
                {
                    CreateRegedit(@"d:\Airway\AirwayVE\Db\");
                }
                string registData ="";
                RegistryKey hkml = Registry.CurrentUser;
                RegistryKey software = hkml.OpenSubKey("SOFTWARE");
                RegistryKey aimdir = software.OpenSubKey("LungCare").OpenSubKey("AirwayNav");
                registData = (string)aimdir.GetValue(name);
                return registData;
            }
    
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="name">AirwayPatientsRootPath</param>
            /// <returns></returns>
            public static bool IsRegeditExit(string name)
            {
                bool _exit = false;
                string[] subkeyNames;
                RegistryKey hkml = Registry.CurrentUser;
                RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
                subkeyNames = software.GetSubKeyNames();
                bool flag = false;
                foreach (string keyName in subkeyNames)
                {
                    if (keyName == "LungCare")
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    RegistryKey LungCare = software.OpenSubKey("LungCare", true);
                    subkeyNames = LungCare.GetSubKeyNames();
                    bool flag1 = false;
                    foreach (string keyName in subkeyNames)
                    {
                        if (keyName == "AirwayNav")
                        {
                            flag1 = true;
                            break;
                        }
                    }
                    if (flag1)
                    {
                        RegistryKey AirwayNav = LungCare.OpenSubKey("AirwayNav", true);
                        subkeyNames = AirwayNav.GetValueNames();
                        bool flag2 = false;
                        foreach (string keyName in subkeyNames)
                        {
                            if (keyName == name)
                            {
                                flag2 = true;
                                _exit = true;
                                return _exit;
                            }
                        }
                        if (!flag2)
                        {
                            _exit = false;
                            return _exit;
                        }
                    }
                    else
                    {
                        _exit = false;
                    }
                }
                else
                {
                    _exit = false;
                }
               
                return _exit;
            }
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="path">"d:\Airway\AirwayVE\Db\"</param>
            public static void CreateRegedit(string value)
            {
                RegistryKey hkml = Registry.CurrentUser;
                RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
                RegistryKey LungCare =  software.CreateSubKey("LungCare");
                RegistryKey AirwayNav =  LungCare.CreateSubKey("AirwayNav");
                AirwayNav.SetValue("AirwayPatientsRootPath", value, RegistryValueKind.String);
            }
    
        }
    }
  • 相关阅读:
    java扫描文件夹下面的所有文件(递归与非递归实现)
    JAVA8 十大新特性详解
    Intellij IDEA创建的Web项目配置Tomcat并启动Maven项目
    Spring官网下载各版本jar包
    史上最全Java面试题(带全部答案)
    深入JVM对象引用
    23种设计模式全解析
    git difftool和mergetool图形化
    Java技术——你真的了解String类的intern()方法吗
    动手实现一个vue中的模态对话框组件
  • 原文地址:https://www.cnblogs.com/liuxinls/p/2974134.html
Copyright © 2011-2022 走看看