private void GetKeyValues(List <RegistryInventory> Results, RegistryKey TargetKey, string TargetValue) { // Get Values of registry items that match search criteria in current key string[] RegistryNameCollection = GetTargetNameCollection(TargetKey, TargetValue); // Get advanced properties if needed IntPtr HKey = TargetKey.Handle.DangerousGetHandle(); string KernelKeyPath = Rule.ShowKernelPath ? RegistryTools.GetKeyNameFromPtr(HKey) : null; string LastModifiedDate = Rule.ShowModifiedTime ? RegistryTools.GetRegistryKeyLastModifiedDate(HKey).ToString() : null; // If RegistryNameCollection doesn't contain an empty string then the default value isn't set. Add a blank result depending on the DefaultValue property if (!RegistryNameCollection.Contains(string.Empty)) { if (RegistryNameCollection.Count() == 0 && (Rule.DefaultValue == DefaultValueOption.OnlyIfKeyIsEmpty || Rule.DefaultValue == DefaultValueOption.OnlyIfValueIsSetOrKeyIsEmpty)) { // Insert a blank (default) value if it is not set but requested Results.Add(new RegistryInventory(TargetKey.ToString(), "(Default)", null, GetRegistryType(RegistryValueKind.String), LastModifiedDate, KernelKeyPath)); } } // Get keys that match the search criteria foreach (string CurrentValueName in RegistryNameCollection) { // Handle (default) value. If NeverInventory or OnlyIfKeyIsEmpty (and key is not empty) continue to next ValueName if (string.IsNullOrEmpty(CurrentValueName)) { if (Rule.DefaultValue == DefaultValueOption.NeverInventory) { continue; } if (Rule.DefaultValue == DefaultValueOption.OnlyIfKeyIsEmpty && RegistryNameCollection.Length > 0) { continue; } } string ValueData = ConvertRegistryValueToString(TargetKey.GetValue(CurrentValueName, "", RegistryValueOptions.DoNotExpandEnvironmentNames)); string ValueType = GetRegistryType(TargetKey.GetValueKind(CurrentValueName)); string ValueName = string.IsNullOrEmpty(CurrentValueName) ? "(Default)" : CurrentValueName; // Handle (default) value based on data. if (string.IsNullOrEmpty(CurrentValueName)) { if (Rule.DefaultValue == DefaultValueOption.OnlyIfValueIsSetOrKeyIsEmpty && (string.IsNullOrEmpty(ValueName) || RegistryNameCollection.Length > 1)) { continue; } if (Rule.DefaultValue == DefaultValueOption.OnlyIfValueIsSet && string.IsNullOrEmpty(ValueName)) { continue; } } // Do not add result if the value is null and InventoryEmptyValue is false if (string.IsNullOrEmpty(ValueData) && !Rule.InventoryEmptyValues) { continue; } Results.Add(new RegistryInventory(TargetKey.ToString(), ValueName, ValueData, ValueType, LastModifiedDate, KernelKeyPath)); } }