/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); } }
/// <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); }
/// <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("注册表类型未定义!"); } }
/// <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); }
/// <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("注册表类型未定义!"); } }
/// <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); }
/// <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)); }
/// <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)); }
/// <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; }
/// <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; }
/// <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; }
/// <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); }
/// <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; }
/// <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; }