void WriteValue(string name, byte[] value, RegistryValueKind valueType) { if (this.hKey != null && !this.hKey.IsInvalid) { int ret = SafeNativeMethods.ClusterRegSetValue(this.hKey, name, valueType, value, (uint)value.Length); if (ret == SafeNativeMethods.ERROR_SUCCESS) { return; } } throw registryExceptionHelper.CreateRegistryWriteException(name, null); }
internal static void DeleteKey(string key, string subKeyToDelete) { RegistryExceptionHelper registryExceptionHelper = new RegistryExceptionHelper(string.Empty, RegistryHive.LocalMachine, key); try { RegistryKey regKey = Registry.LocalMachine.OpenSubKey( key, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl); if (regKey != null) { using (regKey) { string[] subKeys = regKey.GetSubKeyNames(); if (subKeys != null && Array.FindIndex<string>(subKeys, new StringFinder(subKeyToDelete).IsTarget) != -1) { regKey.DeleteSubKeyTree(subKeyToDelete); } } } } catch (SecurityException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } catch (ObjectDisposedException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } catch (ArgumentNullException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } catch (ArgumentException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } catch (UnauthorizedAccessException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } }
internal static void DeleteKey(string key, string subKeyToDelete) { RegistryExceptionHelper registryExceptionHelper = new RegistryExceptionHelper(string.Empty, RegistryHive.LocalMachine, key); try { RegistryKey regKey = Registry.LocalMachine.OpenSubKey( key, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl); if (regKey != null) { using (regKey) { string[] subKeys = regKey.GetSubKeyNames(); if (subKeys != null && Array.FindIndex <string>(subKeys, new StringFinder(subKeyToDelete).IsTarget) != -1) { regKey.DeleteSubKeyTree(subKeyToDelete); } } } } catch (SecurityException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } catch (ObjectDisposedException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } catch (ArgumentNullException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } catch (ArgumentException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } catch (UnauthorizedAccessException e) { throw registryExceptionHelper.CreateRegistryWriteException(subKeyToDelete, e); } }
void DoWriteData(string name, string valueKey, object value, string writeMethod) { EnsureSubKeyExists(); EnsureWriteAccess(); try { ManagementBaseObject inParams = regClassInstance.GetMethodParameters(writeMethod); inParams[InputParameters.DefKey] = this.hiveValue; inParams[InputParameters.SubKeyName] = subKey; inParams[InputParameters.ValueName] = name; inParams[valueKey] = value; ManagementBaseObject outParams = regClassInstance.InvokeMethod(writeMethod, inParams, null); uint ret = (uint)outParams[OutputParameters.ReturnValue]; if (ret != 0) // zero means success { string registryKey = this.subKey; RegistryExceptionHelper.EnsureEndsWithSlash(ref registryKey); registryKey += name; registryExceptionHelper.CreateRegistryWriteException(registryKey, null); } } #pragma warning suppress 56500 catch (Exception e) { // MSDN does not have a spec of possible exceptions for the APIs used above. // To be safe, we should be a bit more generic in catching exceptions if (Utilities.IsCriticalException(e)) { throw; } throw registryExceptionHelper.CreateRegistryAccessException(name, e); } }