public override bool OverrideWithGroupPolicies(ConfigurationSection configurationObject, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey) { called = true; this.configurationObject = configurationObject; this.readGroupPolicies = readGroupPolicies; this.machineKey = machineKey; this.userKey = userKey; IRegistryKey policyKey = GetPolicyKey(machineKey, userKey); if (policyKey != null) { if (!policyKey.GetBoolValue(PolicyValueName).Value) { return false; } TestsConfigurationSection section = configurationObject as TestsConfigurationSection; if (section != null) { try { section.Value = policyKey.GetStringValue(ValuePropertyName); } catch (RegistryAccessException) { } } } return true; }
public void Setup() { mr = new MockRepository(); regSvc = mr.StrictMock<IRegistryService>(); hkcu = mr.StrictMock<IRegistryKey>(); sc = new ServiceContainer(); sc.AddService(typeof(IRegistryService), regSvc); regSvc.Stub(r => r.CurrentUser).Return(hkcu); settingsSvc = new WindowsFormsSettingsService(sc); }
private void LoadPolicyRegistryKeys(string sectionName, out IRegistryKey machineKey, out IRegistryKey userKey) { if (this.readGroupPolicies) { string name = BuildSectionKeyName(this.applicationName, sectionName); machineKey = this.registryAccessor.LocalMachine.OpenSubKey(name); userKey = this.registryAccessor.CurrentUser.OpenSubKey(name); } else { machineKey = null; userKey = null; } }
/// <summary> /// Overrides the <paramref name="configurationObject"/>'s properties with the Group Policy values from the /// registry. /// </summary> /// <param name="configurationObject">The configuration object for instances that must be managed.</param> /// <param name="policyKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration element.</param> /// <remarks>Subclasses implementing this method must retrieve all the override values from the registry /// before making modifications to the <paramref name="configurationObject"/> so any error retrieving /// the override values will cancel policy processing.</remarks> protected override void OverrideWithGroupPolicies(AuthorizationRuleProviderData configurationObject, IRegistryKey policyKey) { String rulesOverride = policyKey.GetStringValue(RulesPropertyName); if (rulesOverride != null) { configurationObject.Rules.Clear(); Dictionary <String, String> attributesDictionary = new Dictionary <string, string>(); KeyValuePairParser.ExtractKeyValueEntries(rulesOverride, attributesDictionary); foreach (KeyValuePair <String, String> kvp in attributesDictionary) { configurationObject.Rules.Add(new AuthorizationRuleData(kvp.Key, kvp.Value)); } } }
protected override void OverrideWithGroupPolicies(CategoryFilterData configurationObject, IRegistryKey policyKey) { CategoryFilterMode?categoryFilterModelOverride = policyKey.GetEnumValue <CategoryFilterMode>(CategoryFilterModePropertyName); configurationObject.CategoryFilters.Clear(); using (IRegistryKey categoryFiltersOverrideKey = policyKey.OpenSubKey(CategoryFiltersKeyName)) { if (categoryFiltersOverrideKey != null) { foreach (String valueName in categoryFiltersOverrideKey.GetValueNames()) { configurationObject.CategoryFilters.Add(new CategoryFilterEntry(valueName)); } } } configurationObject.CategoryFilterMode = categoryFilterModelOverride.Value; }
public static bool ValueExistsAtSubKey(this IRegistryKey key, string subkey, string value) { if (subkey.Length == 0) { throw new ArgumentException("The 'subkey' should not be empty", "subkey"); } using (var k = key.OpenSubKey(subkey)) { if (k == null) { return(false); } // Gets the unnamed value. return((string)k.GetValue(string.Empty) == value); } }
/// <summary> /// Prints a registry key with the given depth. /// </summary> /// <param name="key">The key.</param> /// <param name="depth">The depth.</param> /// <returns>The key, printed at the given depth.</returns> private static string PrintKey(IRegistryKey key, int depth) { var indent = new string(' ', depth *3); // Get the value strings. var values = key.GetValueNames() .Select(v => $"{indent}{(string.IsNullOrEmpty(v) ? "(Default)" : v)} = {key.GetValue(v)}") .OrderBy(s => s); // Get the subkey strings. var subKeys = key.GetSubKeyNames() .OrderBy(sk => sk) .Select(sk => $"{indent}{sk}{Environment.NewLine}{PrintKey(key.OpenSubKey(sk), depth + 1)}"); return(string.Join(Environment.NewLine, values.Concat(subKeys))); }
private bool OverrideWithGroupPoliciesForTraceSource( TraceSourceData traceSourceData, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, String sourceKind) { if (readGroupPolicies) { IRegistryKey policyKey = machineKey != null ? machineKey : userKey; if (policyKey != null) { if (policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value) { return(false); } try { SourceLevels?defaultLevelOverride = policyKey.GetEnumValue <SourceLevels>(SourceDefaultLevelPropertyName); bool? autoFlushOverride = policyKey.GetBoolValue(SourceAutoFlushPropertyName); // the key where the values for the source listeners are stored // might not exist if no listener is selected traceSourceData.TraceListeners.Clear(); using (IRegistryKey listenersOverrideKey = policyKey.OpenSubKey(SourceTraceListenersPropertyName)) { if (listenersOverrideKey != null) { foreach (String valueName in listenersOverrideKey.GetValueNames()) { traceSourceData.TraceListeners.Add(new TraceListenerReferenceData(valueName)); } } } traceSourceData.DefaultLevel = defaultLevelOverride.Value; traceSourceData.AutoFlush = autoFlushOverride.Value; } catch (RegistryAccessException ex) { LogExceptionWhileOverriding(ex); } } } return(true); }
/// <summary> /// Overrides the <paramref name="configurationObject"/>'s properties with the Group Policy values from the /// registry. /// </summary> /// <param name="configurationObject">The configuration object for instances that must be managed.</param> /// <param name="policyKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration element.</param> /// <remarks>Subclasses that manage custom provider's configuration objects with additional properties may /// override this method to override these properties.</remarks> protected override void OverrideWithGroupPolicies(T configurationObject, IRegistryKey policyKey) { Type providerTypeOverride = policyKey.GetTypeValue(ProviderTypePropertyName); String attributesOverride = policyKey.GetStringValue(AttributesPropertyName); configurationObject.Type = providerTypeOverride; configurationObject.Attributes.Clear(); Dictionary <String, String> attributesDictionary = new Dictionary <string, string>(); KeyValuePairParser.ExtractKeyValueEntries(attributesOverride, attributesDictionary); foreach (KeyValuePair <String, String> kvp in attributesDictionary) { configurationObject.Attributes.Add(kvp.Key, kvp.Value); } }
protected override void OverrideWithGroupPolicies(FormattedEventLogTraceListenerData configurationObject, IRegistryKey policyKey) { String formatterOverride = GetFormatterPolicyOverride(policyKey); String logOverride = policyKey.GetStringValue(LogPropertyName); String machineNameOverride = policyKey.GetStringValue(MachineNamePropertyName); String sourceOverride = policyKey.GetStringValue(SourcePropertyName); TraceOptions?traceOutputOptionsOverride = policyKey.GetEnumValue <TraceOptions>(TraceOutputOptionsPropertyName); SourceLevels?filterOverride = policyKey.GetEnumValue <SourceLevels>(FilterPropertyName); configurationObject.Formatter = formatterOverride; configurationObject.Log = logOverride; configurationObject.MachineName = machineNameOverride; configurationObject.Source = sourceOverride; configurationObject.TraceOutputOptions = traceOutputOptionsOverride.Value; configurationObject.Filter = filterOverride.Value; }
public IRegistryKey GetCorrespondingRoot(string keyPath) { IRegistryKey match = null; foreach (IRegistryKey rootKey in new[] { m_registry.ClassesRoot, m_registry.CurrentUser, m_registry.LocalMachine, m_registry.Users, m_registry.CurrentConfig }) { if (match == null && keyPath.StartsWith(rootKey.Name)) { match = rootKey; } else { rootKey.Dispose(); } } return(match); }
// Token: 0x0600032E RID: 814 RVA: 0x00012254 File Offset: 0x00010454 private void SaveToRegistry(string objectXml) { Exception ex; IRegistryKey registryKey = Dependencies.RegistryKeyProvider.TryOpenKey(SharedHelper.AmRegKeyRoot, ref ex); if (ex != null) { throw ex; } if (registryKey != null) { using (registryKey) { registryKey.SetValue("LastKnownGoodConfig", objectXml, RegistryValueKind.String); } } }
/// <summary> /// Retrieves installed R versions. Returns array of strings /// that typically look like 'R-3.2.1' (but development versions /// may also look like '3.3.0 Pre-release' and typically are /// subfolders of 'Program Files\R' /// </summary> public static string[] GetInstalledEngineVersionsFromRegistry() { List <string> enginePaths = new List <string>(); // HKEY_LOCAL_MACHINE\SOFTWARE\R-core // HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\R-core // HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R64\3.3.0 Pre-release using (IRegistryKey hklm = Registry.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) { try { using (var rKey = hklm.OpenSubKey(@"SOFTWARE\R-core\R")) { return(rKey.GetSubKeyNames()); } } catch (Exception) { } } return(new string[0]); }
public MareRegHandlerTests() { RegKeyFake = A.Fake <IRegistryKey>(); A.CallTo(() => RegKeyFake.GetSubKeyNames()).Returns(new string[] { "1" }); A.CallTo(() => RegKeyFake.GetValue("KMD_EnableInternalLargePage", null)).Returns(0); A.CallTo(() => RegKeyFake.GetValue("EnableCrossFireAutoLink", null)).Returns(0); A.CallTo(() => RegKeyFake.GetValue("EnableUlps", null)).Returns(0); A.CallTo(() => RegKeyFake.GetValue("DriverDesc", null)).Returns("FAKE_GPU"); A.CallTo(() => RegKeyFake.SetValue(A <string> .Ignored, A <object> .Ignored, A <RegistryValueKind> .Ignored)).DoesNothing(); A.CallTo(() => RegKeyFake.OpenSubKey(A <string> .Ignored, A <bool> .Ignored)).Returns(RegKeyFake); RegFake = A.Fake <IRegistry>(); A.CallTo(() => RegFake.OpenSubKey(A <string> .Ignored)).Returns(RegKeyFake); MsgBoxFake = A.Fake <IMessageBox>(); A.CallTo(() => MsgBoxFake.Show(A <string> .Ignored)).DoesNothing(); }
private void OverrideWithGroupPoliciesAndGenerateWmiObjectsForSpecialTraceSources( LoggingSettings configurationSection, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, bool generateWmiObjects, ICollection <ConfigurationSetting> wmiSettings) { IRegistryKey machineSpecialSourcesKey = null; IRegistryKey userSpecialSourcesKey = null; try { LoadRegistrySubKeys(SpecialSourcesKeyName, machineKey, userKey, out machineSpecialSourcesKey, out userSpecialSourcesKey); if (configurationSection.SpecialTraceSources.AllEventsTraceSource != null) { OverrideWithGroupPoliciesAndGenerateWmiObjectsForSpecialTraceSource(SpecialSourcesAllEventsKeyName, configurationSection.SpecialTraceSources.AllEventsTraceSource, readGroupPolicies, machineSpecialSourcesKey, userSpecialSourcesKey, generateWmiObjects, wmiSettings, SourceKindAllEvents); } if (configurationSection.SpecialTraceSources.NotProcessedTraceSource != null) { OverrideWithGroupPoliciesAndGenerateWmiObjectsForSpecialTraceSource(SpecialSourcesNotProcessedKeyName, configurationSection.SpecialTraceSources.NotProcessedTraceSource, readGroupPolicies, machineSpecialSourcesKey, userSpecialSourcesKey, generateWmiObjects, wmiSettings, SourceKindNotProcessed); } if (configurationSection.SpecialTraceSources.ErrorsTraceSource != null) { OverrideWithGroupPoliciesAndGenerateWmiObjectsForSpecialTraceSource(SpecialSourcesErrorsKeyName, configurationSection.SpecialTraceSources.ErrorsTraceSource, readGroupPolicies, machineSpecialSourcesKey, userSpecialSourcesKey, generateWmiObjects, wmiSettings, SourceKindErrors); } } finally { ReleaseRegistryKeys(machineSpecialSourcesKey, userSpecialSourcesKey); } }
private bool OverrideWithGroupPoliciesAndGenerateWmiObjectsForCacheManager(CacheManagerData data, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, bool generateWmiObjects, ICollection <ConfigurationSetting> wmiSettings) { if (readGroupPolicies) { IRegistryKey policyKey = machineKey != null ? machineKey : userKey; if (policyKey != null) { if (policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value) { return(false); } try { // cache storage is not overrideable int?expirationPollFrequencyInSecondsOverride = policyKey.GetIntValue(CacheManagerExpirationPollFrequencyInSecondsPropertyName); int?maximumElementsInCacheBeforeScavengingOverride = policyKey.GetIntValue(CacheManagerMaximumElementsInCacheBeforeScavengingPropertyName); int?numberToRemoveWhenScavengingOverride = policyKey.GetIntValue(CacheManagerNumberToRemoveWhenScavengingPropertyName); data.ExpirationPollFrequencyInSeconds = expirationPollFrequencyInSecondsOverride.Value; data.MaximumElementsInCacheBeforeScavenging = maximumElementsInCacheBeforeScavengingOverride.Value; data.NumberToRemoveWhenScavenging = numberToRemoveWhenScavengingOverride.Value; } catch (RegistryAccessException ex) { LogExceptionWhileOverriding(ex); } } } if (generateWmiObjects) { wmiSettings.Add( new CacheManagerSetting(data.Name, data.CacheStorage, data.ExpirationPollFrequencyInSeconds, data.MaximumElementsInCacheBeforeScavenging, data.NumberToRemoveWhenScavenging)); } return(true); }
private string RecurseFirstSubkey(IRegistryKey rCoreKey, StringBuilder logger) { string[] subKeyNames = rCoreKey.GetSubKeyNames(); if (subKeyNames.Length > 0) { Array.Sort(subKeyNames); var versionNum = subKeyNames.Last(); // gets the latest version of R installed and registered. //versionNum = subKeyNames.First(); // TEMP... var rVersionCoreKey = rCoreKey.OpenSubKey(versionNum); doLogSetEnvVarInfo("As a last resort, trying to recurse into " + rVersionCoreKey, logger); return(GetRInstallPathFromRCoreKegKey(rVersionCoreKey, logger)); } else { doLogSetEnvVarWarn("No sub-key found under " + rCoreKey, logger); return(null); } }
/// <summary> /// /// </summary> /// <typeparam name="TEnum"></typeparam> /// <param name="policyKey"></param> /// <param name="propertyName"></param> /// <returns></returns> protected TEnum?GetFlagsEnumOverride <TEnum>(IRegistryKey policyKey, string propertyName) where TEnum : struct { string[] allValueNames = new string[0]; using (var propertyKey = policyKey.OpenSubKey(propertyName)) { if (propertyKey != null) { allValueNames = propertyKey.GetValueNames(); } } var convertedValues = allValueNames.Select(vn => Convert.ToUInt64(Enum.Parse(typeof(TEnum), vn))); var mergedValues = convertedValues.Aggregate <ulong, ulong>(0, (acc, v) => acc | v); return((TEnum)Enum.ToObject(typeof(TEnum), mergedValues)); }
private TimeSpan GetTimeSpanOverride(IRegistryKey policyKey, String propertyName) { TimeSpan result; String overrideValue = policyKey.GetStringValue(propertyName); if (!TimeSpan.TryParse(overrideValue, out result)) { throw new RegistryAccessException( String.Format(Resources.Culture, Resources.ExceptionErrorValueNotTimeSpan, policyKey.Name, propertyName, overrideValue)); } return(result); }
/// <summary> /// Overrides the <paramref name="configurationSection"/>'s configuration elements' properties /// with the Group Policy values from the registry, if any, and creates the <see cref="ConfigurationSetting"/> /// instances that describe these configuration elements. /// </summary> /// <param name="configurationSection">The configuration section that must be managed.</param> /// <param name="readGroupPolicies"><see langword="true"/> if Group Policy overrides must be applied; otherwise, /// <see langword="false"/>.</param> /// <param name="machineKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration section at the machine level, or <see langword="null"/> /// if there is no such registry key.</param> /// <param name="userKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration section at the user level, or <see langword="null"/> /// if there is no such registry key.</param> /// <param name="generateWmiObjects"><see langword="true"/> if WMI objects must be generated; otherwise, /// <see langword="false"/>.</param> /// <param name="wmiSettings">A collection to where the generated WMI objects are to be added.</param> protected override void OverrideWithGroupPoliciesAndGenerateWmiObjectsForConfigurationElements(ExceptionHandlingSettings configurationSection, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, bool generateWmiObjects, ICollection <ConfigurationSetting> wmiSettings) { IRegistryKey machinePoliciesKey = null; IRegistryKey userPoliciesKey = null; try { LoadRegistrySubKeys(PoliciesKeyName, machineKey, userKey, out machinePoliciesKey, out userPoliciesKey); foreach (ExceptionPolicyData policy in configurationSection.ExceptionPolicies) { IRegistryKey machinePolicyKey = null; IRegistryKey userPolicyKey = null; try { LoadRegistrySubKeys(policy.Name, machinePoliciesKey, userPoliciesKey, out machinePolicyKey, out userPolicyKey); OverrideWithGroupPoliciesAndGenerateWmiObjectsForPolicy(policy, readGroupPolicies, machinePolicyKey, userPolicyKey, generateWmiObjects, wmiSettings); if (generateWmiObjects) { wmiSettings.Add(new ExceptionPolicySetting(policy.Name)); } } finally { ReleaseRegistryKeys(machinePolicyKey, userPolicyKey); } } } finally { ReleaseRegistryKeys(machinePoliciesKey, userPoliciesKey); } }
private void AddArchitectVersionKeys(IRegistryKey softwareKey, IRegistryKey softwareWow64Key) { var subkeys = new List <string>(); var subkeysWow64 = new List <string>(); foreach (var pdfArchitectVersion in _pdfArchitectVersions) { var versionKey = Substitute.For <IRegistryKey>(); versionKey.GetValue("DisplayName").Returns(pdfArchitectVersion.DisplayName); versionKey.GetValue("InstallLocation").Returns(pdfArchitectVersion.InstallLocation); versionKey.GetValue("Publisher").Returns("pdfforge"); var version = pdfArchitectVersion; IRegistryKey mockKey; IList <string> subkeyList; if (pdfArchitectVersion.IsWow64) { mockKey = softwareWow64Key; subkeyList = subkeysWow64; } else { mockKey = softwareKey; subkeyList = subkeys; } subkeyList.Add(pdfArchitectVersion.SubkeyName); if (pdfArchitectVersion.ThrowsException) { mockKey.OpenSubKey(version.SubkeyName).Returns(x => throw new IOException()); } else { mockKey.OpenSubKey(version.SubkeyName).Returns(versionKey); } } softwareKey.GetSubKeyNames().Returns(subkeys.ToArray()); softwareWow64Key.GetSubKeyNames().Returns(subkeysWow64.ToArray()); }
private static string GetRPathFromMRS() { // First check that MRS is present on the machine. bool mrsInstalled = false; try { using (var hklm = Registry.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) { using (var key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\130\sql_shared_mr")) { var path = (string)key.GetValue("Path"); if (!string.IsNullOrEmpty(path) && path.Contains(rServer)) { mrsInstalled = true; } } } } catch (Exception) { } // If yes, check 32-bit registry for R engine installed by the R Server. // TODO: remove this when MRS starts writing 64-bit keys. if (mrsInstalled) { using (IRegistryKey hklm = Registry.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) { try { using (var key = hklm.OpenSubKey(@"SOFTWARE\R-core\R64")) { foreach (var keyName in key.GetSubKeyNames()) { using (var rsKey = key.OpenSubKey(keyName)) { try { var path = (string)rsKey.GetValue("InstallPath"); if (!string.IsNullOrEmpty(path) && path.Contains(rServer)) { return(path); } } catch (Exception) { } } } } } catch (Exception) { } } } return(null); }
/// <summary> /// Overrides the <paramref name="configurationObject"/>'s properties with the Group Policy values from the /// registry, if any, and creates the <see cref="ConfigurationSetting"/> instances that describe the /// configurationObject. /// </summary> /// <param name="configurationObject">The configuration object for instances that must be managed.</param> /// <param name="readGroupPolicies"><see langword="true"/> if Group Policy overrides must be applied; otherwise, /// <see langword="false"/>.</param> /// <param name="machineKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration element at the machine level, or <see langword="null"/> /// if there is no such registry key.</param> /// <param name="userKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration element at the user level, or <see langword="null"/> /// if there is no such registry key.</param> /// <param name="generateWmiObjects"><see langword="true"/> if WMI objects must be generated; otherwise, /// <see langword="false"/>.</param> /// <param name="wmiSettings">A collection to where the generated WMI objects are to be added.</param> /// <returns><see langword="true"/> if the policy settings do not disable the configuration element, otherwise /// <see langword="false"/>.</returns> /// <exception cref="ArgumentException">when the type of <paramref name="configurationObject"/> is not /// the type <typeparamref name="T"/>.</exception> /// <remarks> /// Provides a default implementation that performs appropriate logging of errors when processing /// policy overrides. /// </remarks> /// <seealso cref="ConfigurationElementManageabilityProvider.OverrideWithGroupPoliciesAndGenerateWmiObjects">ConfigurationElementManageabilityProvider.OverrideWithGroupPoliciesAndGenerateWmiObjects</seealso> /// <seealso cref="ConfigurationElementManageabilityProviderBase{T}.OverrideWithGroupPolicies"/> /// <seealso cref="ConfigurationElementManageabilityProviderBase{T}.GenerateWmiObjects"/> protected internal sealed override bool OverrideWithGroupPoliciesAndGenerateWmiObjects(ConfigurationElement configurationObject, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, bool generateWmiObjects, ICollection <ConfigurationSetting> wmiSettings) { T data = configurationObject as T; if (data == null) { throw new ArgumentException( String.Format(CultureInfo.CurrentUICulture, Resources.ConfigurationElementOfWrongType, typeof(T).FullName, configurationObject.GetType().FullName), "configurationObject"); } if (readGroupPolicies) { IRegistryKey policyKey = machineKey != null ? machineKey : userKey; if (policyKey != null) { // the keys for some elements might not be the keys associated to a policy, // but hold the policy values for the element when policies for multiple // elements are combined. if (policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value) { return(false); } try { OverrideWithGroupPolicies(data, policyKey); } catch (Exception ex) { LogExceptionWhileOverriding(ex); } } } if (generateWmiObjects) { GenerateWmiObjects(data, wmiSettings); } return(true); }
bool OverrideWithGroupPoliciesAndGenerateWmiObjectsForCacheManager(CacheManagerDataBase cacheManagerDataBase, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey) { if (readGroupPolicies) { IRegistryKey policyKey = machineKey != null ? machineKey : userKey; if (policyKey != null) { if (policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value) { return(false); } try { if (cacheManagerDataBase is CacheManagerData) { CacheManagerData cacheManagerData = (CacheManagerData)cacheManagerDataBase; // cache storage is not overrideable int?expirationPollFrequencyInSecondsOverride = policyKey.GetIntValue(CacheManagerExpirationPollFrequencyInSecondsPropertyName); int?maximumElementsInCacheBeforeScavengingOverride = policyKey.GetIntValue(CacheManagerMaximumElementsInCacheBeforeScavengingPropertyName); int?numberToRemoveWhenScavengingOverride = policyKey.GetIntValue(CacheManagerNumberToRemoveWhenScavengingPropertyName); cacheManagerData.ExpirationPollFrequencyInSeconds = expirationPollFrequencyInSecondsOverride.Value; cacheManagerData.MaximumElementsInCacheBeforeScavenging = maximumElementsInCacheBeforeScavengingOverride.Value; cacheManagerData.NumberToRemoveWhenScavenging = numberToRemoveWhenScavengingOverride.Value; } } catch (RegistryAccessException ex) { LogExceptionWhileOverriding(ex); } } } return(true); }
// Token: 0x0600032F RID: 815 RVA: 0x000122A8 File Offset: 0x000104A8 private static string GetFromRegistry() { Exception ex; IRegistryKey registryKey = Dependencies.RegistryKeyProvider.TryOpenKey(SharedHelper.AmRegKeyRoot, ref ex); if (ex != null) { throw ex; } string result = string.Empty; if (registryKey != null) { using (registryKey) { result = (string)registryKey.GetValue("LastKnownGoodConfig", string.Empty); } } return(result); }
protected override void OverrideWithGroupPolicies(RollOnceTraceListenerData configObj, IRegistryKey policyKey) { string filenameOverride = policyKey.GetStringValue(FilenamePropertyName); string headerOverride = policyKey.GetStringValue(HeaderPropertyName); string footerOverride = policyKey.GetStringValue(FooterPropertyName); int? maxLogs = policyKey.GetIntValue(MaxLogsPropertyName); string formatterOverride = GetFormatterPolicyOverride(policyKey); TraceOptions?traceOutputOptionsO = policyKey.GetEnumValue <TraceOptions>(TraceOutputOptionsPropertyName); SourceLevels?filterOverride = policyKey.GetEnumValue <SourceLevels>(FilterPropertyName); configObj.FileName = filenameOverride; configObj.Header = headerOverride; configObj.Footer = footerOverride; configObj.Formatter = formatterOverride; configObj.MaxLogs = maxLogs.Value; configObj.TraceOutputOptions = traceOutputOptionsO.Value; configObj.Filter = filterOverride.Value; }
/// <summary> /// Overrides the <paramref name="configurationSection"/>'s configuration elements' properties /// with the Group Policy values from the registry, if any. /// </summary> /// <param name="configurationSection">The configuration section that must be managed.</param> /// <param name="readGroupPolicies"><see langword="true"/> if Group Policy overrides must be applied; otherwise, /// <see langword="false"/>.</param> /// <param name="machineKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration section at the machine level, or <see langword="null"/> /// if there is no such registry key.</param> /// <param name="userKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration section at the user level, or <see langword="null"/> /// if there is no such registry key.</param> protected override void OverrideWithGroupPoliciesForConfigurationElements( LoggingSettings configurationSection, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey) { OverrideWithGroupPoliciesForCategoryTraceSources(configurationSection, readGroupPolicies, machineKey, userKey); OverrideWithGroupPoliciesForSpecialTraceSources(configurationSection, readGroupPolicies, machineKey, userKey); OverrideWithGroupPoliciesForElementCollection(configurationSection.LogFilters, LogFiltersKeyName, readGroupPolicies, machineKey, userKey); OverrideWithGroupPoliciesForElementCollection(configurationSection.Formatters, LogFormattersKeyName, readGroupPolicies, machineKey, userKey); OverrideWithGroupPoliciesForElementCollection(configurationSection.TraceListeners, TraceListenersKeyName, readGroupPolicies, machineKey, userKey); }
private void RecurseCopyKey(IRegistryKey sourceKey, IRegistryKey destinationKey) { //copy all the values foreach (var valueName in sourceKey.GetValueNames()) { var objValue = sourceKey.GetValue(valueName); var valKind = sourceKey.GetValueKind(valueName); destinationKey.SetValue(valueName, objValue, valKind); } //For Each subKey //Create a new subKey in destinationKey //Call myself foreach (var sourceSubKeyName in sourceKey.GetSubKeyNames()) { var sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName); var destSubKey = destinationKey.CreateSubKey(sourceSubKeyName); RecurseCopyKey(sourceSubKey, destSubKey); } }
bool OverrideWithGroupPoliciesAndGenerateWmiObjectsForOracleConnection(OracleConnectionData connectionData, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, bool generateWmiObjects, ICollection <ConfigurationSetting> wmiSettings) { if (readGroupPolicies) { IRegistryKey policyKey = machineKey ?? userKey; if (policyKey != null) { if (policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value) { return(false); } try { String packagesOverride = policyKey.GetStringValue(PackagesPropertyName); connectionData.Packages.Clear(); Dictionary <String, String> packagesDictionary = new Dictionary <string, string>(); KeyValuePairParser.ExtractKeyValueEntries(packagesOverride, packagesDictionary); foreach (KeyValuePair <String, String> kvp in packagesDictionary) { connectionData.Packages.Add(new OraclePackageData(kvp.Key, kvp.Value)); } } catch (RegistryAccessException ex) { LogExceptionWhileOverriding(ex); } } } if (generateWmiObjects) { OracleConnectionSettingsWmiMapper.GenerateOracleConnectionSettingWmiObjects(connectionData, wmiSettings); } return(true); }
public IRegistryKey OpenKey(string keyPath, RegistryKeyPermissionCheck permissionCheck = default, RegistryRights rights = default) { IRegistryKey cleanUpKey = null; try { IRegistryKey root = GetCorrespondingRoot(keyPath); string openKeyName = keyPath.MustEndWith(RegistryPathDelimiter).Remove(root.Name.MustEndWith(RegistryPathDelimiter)); if (openKeyName.IsNullOrWhitespace()) { return(root); } cleanUpKey = root; IRegistryKey key = root.OpenSubKey(openKeyName, permissionCheck, rights); return(key); } finally { cleanUpKey?.Dispose(); } }
static void ReleasePolicyRegistryKeys(IRegistryKey machineKey, IRegistryKey userKey) { if (machineKey != null) { try { machineKey.Close(); } catch (Exception) {} } if (userKey != null) { try { userKey.Close(); } catch (Exception) {} } }
// Token: 0x06000818 RID: 2072 RVA: 0x00027444 File Offset: 0x00025644 private bool ReadProperty <T>(string keyName, string propertyName, out T foundValue, T defaultValue) { bool result = false; foundValue = defaultValue; Exception ex = null; using (IRegistryKey registryKey = SharedDependencies.RegistryKeyProvider.TryOpenKey(keyName, ref ex)) { if (registryKey != null) { object value = registryKey.GetValue(propertyName, defaultValue); if (value != null) { result = true; foundValue = (T)((object)value); } } } return(result); }
protected override void OverrideWithGroupPoliciesForConfigurationElements( DatabaseSettings configurationSection, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey) { List <DbProviderMapping> dbProviderMappingList = new List <DbProviderMapping>(); IRegistryKey machineSubKey1 = (IRegistryKey)null; IRegistryKey userSubKey1 = (IRegistryKey)null; try { ConfigurationSectionManageabilityProvider.LoadRegistrySubKeys("providerMappings", machineKey, userKey, out machineSubKey1, out userSubKey1); foreach (DbProviderMapping providerMapping in configurationSection.ProviderMappings) { IRegistryKey machineSubKey2 = (IRegistryKey)null; IRegistryKey userSubKey2 = (IRegistryKey)null; try { ConfigurationSectionManageabilityProvider.LoadRegistrySubKeys(providerMapping.Name, machineSubKey1, userSubKey1, out machineSubKey2, out userSubKey2); if (!this.OverrideWithGroupPoliciesForDbProviderMapping(providerMapping, readGroupPolicies, machineSubKey2, userSubKey2)) { dbProviderMappingList.Add(providerMapping); } } finally { ConfigurationSectionManageabilityProvider.ReleaseRegistryKeys(machineSubKey2, userSubKey2); } } } finally { ConfigurationSectionManageabilityProvider.ReleaseRegistryKeys(machineSubKey1, userSubKey1); } foreach (DbProviderMapping dbProviderMapping in dbProviderMappingList) { configurationSection.ProviderMappings.Remove(dbProviderMapping.Name); } }
private static void ReleasePolicyRegistryKeys(IRegistryKey machineKey, IRegistryKey userKey) { if (machineKey != null) { try { machineKey.Close(); } catch (Exception) { } } if (userKey != null) { try { userKey.Close(); } catch (Exception) { } } }
public override bool OverrideWithGroupPolicies(ConfigurationElement configurationObject, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey) { called = true; configurationObjects.Add(configurationObject); this.readGroupPolicies = readGroupPolicies; this.machineKey = machineKey; this.userKey = userKey; if (readGroupPolicies) { IRegistryKey policyKey = machineKey != null ? machineKey : userKey; if (policyKey != null && policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value) { return false; } } return true; }
/// <summary> /// Overrides the <paramref name="configurationObject"/>'s properties with the Group Policy values from the /// registry, if any. /// </summary> /// <param name="configurationObject">The configuration object for instances that must be managed.</param> /// <param name="readGroupPolicies"><see langword="true"/> if Group Policy overrides must be applied; otherwise, /// <see langword="false"/>.</param> /// <param name="machineKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration element at the machine level, or <see langword="null"/> /// if there is no such registry key.</param> /// <param name="userKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the /// configuration element at the user level, or <see langword="null"/> /// if there is no such registry key.</param> /// <returns><see langword="true"/> if the policy settings do not disable the configuration element, otherwise /// <see langword="false"/>.</returns> /// <exception cref="ArgumentException">when the type of <paramref name="configurationObject"/> is not /// the type.</exception> public abstract bool OverrideWithGroupPolicies(ConfigurationElement configurationObject, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey);
/// <summary> /// Constructor of the class. /// </summary> /// <param name="registryKey"></param> public GlobalHotkeyManagerAutostartRegistryKeyInfo([NotNull] IRegistryKey registryKey) { if (registryKey == null) throw new ArgumentNullException("registryKey"); _registryKey = registryKey; }
protected internal abstract bool OverrideWithGroupPoliciesAndGenerateWmiObjects(ConfigurationElement configurationObject, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, bool generateWmiObjects, ICollection<ConfigurationSetting> wmiSettings);
/// <summary> /// Constructor of the class /// </summary> /// <param name="registryKey"></param> public CurrentApplicationStartupManager([NotNull] IRegistryKey registryKey) { if (registryKey == null) throw new ArgumentNullException("registryKey"); _registryKey = registryKey; }
internal KillBitHelper(IRegistryKey localMachine) { this._localMachine = localMachine; }