static string GetRegistryKeyBase(string machineName, RegistryHive registryHive) { string registryBase = Utilities.IsLocalMachineName(machineName) ? string.Empty : SR.GetString(SR.RemoteRegistryFormat, machineName); switch (registryHive) { case RegistryHive.ClassesRoot: registryBase += Registry.ClassesRoot.Name; break; case RegistryHive.CurrentUser: registryBase += Registry.CurrentUser.Name; break; case RegistryHive.LocalMachine: registryBase += Registry.LocalMachine.Name; break; default: // We do not support other values here System.Diagnostics.Debug.Assert(false, "registryHive is not supported"); break; } RegistryExceptionHelper.EnsureEndsWithSlash(ref registryBase); return(registryBase); }
ClusterRegistryConfigurationProvider(SafeHKey key, string registryKey) { this.hKey = key; this.registryExceptionHelper = new RegistryExceptionHelper(registryKey); this.registryKey = registryKey; RegistryExceptionHelper.EnsureEndsWithSlash(ref registryKey); }
internal StdRegProviderWrapper OpenKey(string subKey) { string s = this.subKey; RegistryExceptionHelper.EnsureEndsWithSlash(ref s); s += subKey; return(new StdRegProviderWrapper(this.hiveValue, s, regClassInstance)); }
internal ClusterRegistryConfigurationProvider(SafeHResource hResource, string key) { SafeHKey rootKey = SafeNativeMethods.GetClusterResourceKey(hResource, RegistryRights.ReadKey | RegistryRights.EnumerateSubKeys | RegistryRights.QueryValues); if (rootKey.IsInvalid) { int lastError = Marshal.GetLastWin32Error(); throw new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.CannotOpenClusterRegistry, lastError)); } if (string.IsNullOrEmpty(key)) { hKey = rootKey; } else { using (rootKey) { int disposition; int ret = SafeNativeMethods.ClusterRegCreateKey(rootKey, key, SafeNativeMethods.REG_OPTION_NON_VOLATILE, RegistryRights.FullControl, IntPtr.Zero, out this.hKey, out disposition); if (ret != SafeNativeMethods.ERROR_SUCCESS) { throw new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.CannotOpenClusterRegistry, ret)); } } } registryExceptionHelper = new RegistryExceptionHelper(key); this.registryKey = key; RegistryExceptionHelper.EnsureEndsWithSlash(ref this.registryKey); }
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); } }