예제 #1
0
        /// <summary>
        /// 设置注册表项值
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <param name="keyValueName">值名称</param>
        /// <param name="keyValue">值</param>
        /// <returns></returns>
        public static bool SetRegistryValue(WRegisterRootKeyType rootKeyType, string keyPath, string keyValueName, string keyValue)
        {
            RegistryKey key = GetRegistryKey(rootKeyType, keyPath);

            key.SetValue(keyValueName, keyValue);
            return(true);
        }
예제 #2
0
        /// <summary>
        /// 在指定注册表项下创建注册表子项
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <param name="keyValueName">要添加的注册表项值名称</param>
        /// <param name="keyValue">要添加的注册表项值</param>
        /// <returns></returns>
        public static RegistryKey CreateRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath, string keyValueName, string keyValue)
        {
            RegistryKey returnKey = CreateRegistryKey(rootKeyType, keyPath);

            returnKey.SetValue(keyValueName, keyValue);
            return(returnKey);
        }
예제 #3
0
        /// <summary>
        /// 获取注册表项指定值
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <param name="keyName">要获得值的注册表值名称</param>
        /// <returns></returns>
        public static string GetRegistryValue(WRegisterRootKeyType rootKeyType, string keyPath, string keyName)
        {
            RegistryKey key = GetRegistryKey(rootKeyType, keyPath);

            if (IsKeyHaveValue(key, keyName))
            {
                return(key.GetValue(keyName).ToString());
            }
            return(null);
        }
예제 #4
0
        /// <summary>
        /// 删除注册表项值
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <param name="keyValueName">值名称</param>
        /// <returns></returns>
        public static bool DeleteRegistryValue(WRegisterRootKeyType rootKeyType, string keyPath, string keyValueName)
        {
            RegistryKey key = GetRegistryKey(rootKeyType, keyPath);

            if (IsKeyHaveValue(key, keyValueName))
            {
                key.DeleteValue(keyValueName);
                return(true);
            }
            return(false);
        }
예제 #5
0
 /// <summary>
 /// 在指定注册表项下创建注册表子项
 /// </summary>
 /// <param name="rootKeyType">注册表根节点项类型</param>
 /// <param name="keyPath">注册表路径</param>
 /// <returns></returns>
 public static RegistryKey CreateRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath)
 {
     try
     {
         RegistryKey rootKey = GetRootRegisterKey(rootKeyType);
         return(rootKey.CreateSubKey(keyPath));
     }
     catch
     {
         return(null);
     }
 }
예제 #6
0
        /// <summary>
        /// 删除注册表子项
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <returns></returns>
        public static bool DeleteRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath, string keyName)
        {
            RegistryKey rootKey   = GetRootRegisterKey(rootKeyType);
            RegistryKey deleteKey = rootKey.OpenSubKey(keyPath);

            if (IsKeyHaveSubKey(deleteKey, keyName))
            {
                deleteKey.DeleteSubKey(keyName);
                return(true);
            }
            return(false);
        }
예제 #7
0
 /// <summary>
 /// 获得根节点注册表
 /// </summary>
 /// <param name="rootKeyType">根节点类型</param>
 /// <returns></returns>
 public static RegistryKey GetRootRegisterKey(WRegisterRootKeyType rootKeyType)
 {
     switch (rootKeyType)
     {
         case WRegisterRootKeyType.HKEY_CLASSES_ROOT:
             return Registry.ClassesRoot;
         case WRegisterRootKeyType.HKEY_CURRENT_CONFIG:
             return Registry.CurrentConfig;
         case WRegisterRootKeyType.HKEY_CURRENT_USER:
             return Registry.CurrentUser;
         case WRegisterRootKeyType.HKEY_LOCAL_MACHINE:
             return Registry.LocalMachine;
         default:
             throw new Exception("注册表类型未定义!");
     }
 }
예제 #8
0
        /// <summary>
        /// 设置注册表项值
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <param name="keyValueName">值名称</param>
        /// <param name="keyValue">值</param>
        /// <returns></returns>
        public static bool SetRegistryValue(WRegisterRootKeyType rootKeyType, string keyPath, string keyValueName, string keyValue)
        {
            RegistryKey key = GetRegistryKey(rootKeyType, keyPath);

            if (key == null)
            {
                key = CreateRegistryKey(rootKeyType, keyPath);
            }
            try
            {
                key.SetValue(keyValueName, keyValue);
            }
            catch (Exception ex)
            {
                XErrorLogTool.WriteLog(ex.ToString());
                return(false);
            }
            return(true);
        }
예제 #9
0
        /// <summary>
        /// 获得根节点注册表
        /// </summary>
        /// <param name="rootKeyType">根节点类型</param>
        /// <returns></returns>
        public static RegistryKey GetRootRegisterKey(WRegisterRootKeyType rootKeyType)
        {
            switch (rootKeyType)
            {
            case WRegisterRootKeyType.HKEY_CLASSES_ROOT:
                return(Registry.ClassesRoot);

            case WRegisterRootKeyType.HKEY_CURRENT_CONFIG:
                return(Registry.CurrentConfig);

            case WRegisterRootKeyType.HKEY_CURRENT_USER:
                return(Registry.CurrentUser);

            case WRegisterRootKeyType.HKEY_LOCAL_MACHINE:
                return(Registry.LocalMachine);

            default:
                throw new Exception("注册表类型未定义!");
            }
        }
예제 #10
0
 /// <summary>
 /// 获取注册表项
 /// </summary>
 /// <param name="rootKeyType">注册表根节点项类型</param>
 /// <param name="keyPath">注册表路径</param>
 /// <returns></returns>
 public static RegistryKey GetRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath)
 {
     RegistryKey rootKey = GetRootRegisterKey(rootKeyType);
     return rootKey.OpenSubKey(keyPath);
 }
예제 #11
0
        /// <summary>
        /// 获取注册表项
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <returns></returns>
        public static RegistryKey GetRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath)
        {
            RegistryKey rootKey = GetRootRegisterKey(rootKeyType);

            return(rootKey.OpenSubKey(keyPath, true));
        }
예제 #12
0
        /// <summary>
        /// 在指定注册表项下创建注册表子项
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <returns></returns>
        public static RegistryKey CreateRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath)
        {
            RegistryKey rootKey = GetRootRegisterKey(rootKeyType);

            return(CreateRegistryKey(rootKey, keyPath));
        }
예제 #13
0
        /// <summary>
        /// 获取注册表项指定值
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <param name="keyName">要获得值的注册表值名称</param>
        /// <returns></returns>
        public static string GetRegistryValue(WRegisterRootKeyType rootKeyType, string keyPath, string keyName)
        {
            RegistryKey key = GetRegistryKey(rootKeyType, keyPath);
            if (key == null) return null;

            if (IsKeyHaveValue(key, keyName))
            {
                return key.GetValue(keyName).ToString();
            }
            return null;
        }
예제 #14
0
        /// <summary>
        /// 删除注册表子项
        /// </summary>
        /// <param name="rootKeyType">注册表根节点项类型</param>
        /// <param name="keyPath">注册表路径</param>
        /// <returns></returns>
        public static bool DeleteRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath, string keyName)
        {
            RegistryKey rootKey = GetRootRegisterKey(rootKeyType);
            RegistryKey deleteKey = rootKey.OpenSubKey(keyPath);

            if (IsKeyHaveSubKey(deleteKey, keyName))
            {
                deleteKey.DeleteSubKey(keyName);
                return true;
            }
            return false;
        }
예제 #15
0
 /// <summary>
 /// 在指定注册表项下创建注册表子项
 /// </summary>
 /// <param name="rootKeyType">注册表根节点项类型</param>
 /// <param name="keyPath">注册表路径</param>
 /// <param name="keyValueName">要添加的注册表项值名称</param>
 /// <param name="keyValue">要添加的注册表项值</param>
 /// <returns></returns>
 public static RegistryKey CreateRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath, string keyValueName, string keyValue)
 {
     RegistryKey returnKey = CreateRegistryKey(rootKeyType, keyPath);
     returnKey.SetValue(keyValueName, keyValue);
     return returnKey;
 }
예제 #16
0
 /// <summary>
 /// 在指定注册表项下创建注册表子项
 /// </summary>
 /// <param name="rootKeyType">注册表根节点项类型</param>
 /// <param name="keyPath">注册表路径</param>
 /// <returns></returns>
 public static RegistryKey CreateRegistryKey(WRegisterRootKeyType rootKeyType, string keyPath)
 {
     RegistryKey rootKey = GetRootRegisterKey(rootKeyType);
     return CreateRegistryKey(rootKey, keyPath);
 }
예제 #17
0
 /// <summary>
 /// 删除注册表项值
 /// </summary>
 /// <param name="rootKeyType">注册表根节点项类型</param>
 /// <param name="keyPath">注册表路径</param>
 /// <param name="keyValueName">值名称</param>
 /// <returns></returns>
 public static bool DeleteRegistryValue(WRegisterRootKeyType rootKeyType, string keyPath, string keyValueName)
 {
     RegistryKey key = GetRegistryKey(rootKeyType, keyPath);
     if (IsKeyHaveValue(key, keyValueName))
     {
         key.DeleteValue(keyValueName);
         return true;
     }
     return false;
 }
예제 #18
0
 /// <summary>
 /// 设置注册表项值
 /// </summary>
 /// <param name="rootKeyType">注册表根节点项类型</param>
 /// <param name="keyPath">注册表路径</param>
 /// <param name="keyValueName">值名称</param>
 /// <param name="keyValue">值</param>
 /// <returns></returns>
 public static bool SetRegistryValue(WRegisterRootKeyType rootKeyType, string keyPath, string keyValueName, string keyValue)
 {
     RegistryKey key = GetRegistryKey(rootKeyType, keyPath);
     key.SetValue(keyValueName, keyValue);
     return true;
 }