public PolicyItemLocalCheck() { ActualPolicy = new PolicyItemCheckItem(); DiffContextPolicy = new PolicyItemCheckItem(); NonPolicy = new PolicyItemCheckItem(); DiffContextNonPolicy = new PolicyItemCheckItem(); }
private PolicyItemCheckItem TestItem(RegistryKey passedRoot, string passedKey, string passedValue, PolicyItem item) { PolicyItemCheckItem returnValue = new PolicyItemCheckItem(); try { RegistryKey rk = passedRoot.OpenSubKey(passedKey); object Value = rk.GetValue(passedValue); if (Value != null) { RegistryValueKind rvk = rk.GetValueKind(item.Value); if (ConvertRegKindToString(rvk).ToString().Equals(item.StringType)) { if (rvk.Equals(RegistryValueKind.Binary)) { byte[] bytes = (byte[])Value; string vs = ""; for (int i = 0; i < bytes.Length; i++) { vs += String.Format("{0:X2}", bytes[i]); } returnValue.LocalValue = vs; if (vs.Equals(item.Data)) { returnValue.Exists = PolicyItem.ITEM_EXISTS_SAME; returnValue.ExistsInfo = "Values Match"; } else { returnValue.Exists = PolicyItem.ITEM_EXISTS_VALUE_DIFFERS; returnValue.ExistsInfo = "Local value " + vs; } } else if (rvk.Equals(RegistryValueKind.ExpandString)) { returnValue.LocalValue = Value.ToString(); if (Value.ToString().Equals(item.Data)) { returnValue.Exists = PolicyItem.ITEM_EXISTS_SAME; returnValue.ExistsInfo = "Values Match"; } else { if (Environment.ExpandEnvironmentVariables(item.Data).Equals(Value.ToString())) { returnValue.Exists = PolicyItem.ITEM_EXISTS_SAME; returnValue.ExistsInfo = "Values Match"; } else { returnValue.Exists = PolicyItem.ITEM_EXISTS_VALUE_DIFFERS; returnValue.ExistsInfo = "Local value " + Value; } } } else if (rvk.Equals(RegistryValueKind.MultiString)) { string[] regItems = item.Data.Split('\0').Where(t => t.Length > 0).ToArray(); if (Value is string[] && regItems.SequenceEqual((string[])(Value))) { returnValue.LocalValue = Value.ToString(); returnValue.Exists = PolicyItem.ITEM_EXISTS_SAME; returnValue.ExistsInfo = "Values Match"; } else { returnValue.Exists = PolicyItem.ITEM_EXISTS_VALUE_DIFFERS; returnValue.ExistsInfo = "Local value " + Value; returnValue.LocalValue = Value.ToString(); } } else if (Value.ToString().Equals(item.Data)) { returnValue.LocalValue = Value.ToString(); returnValue.Exists = PolicyItem.ITEM_EXISTS_SAME; returnValue.ExistsInfo = "Values Match"; } else { returnValue.Exists = PolicyItem.ITEM_EXISTS_VALUE_DIFFERS; returnValue.ExistsInfo = "Local value " + Value; returnValue.LocalValue = Value.ToString(); } } else { returnValue.Exists = PolicyItem.ITEM_EXISTS_TYPE_DIFFERS; returnValue.ExistsInfo = "Local type " + ConvertRegKindToString(rvk).ToString(); returnValue.LocalValue = item.Data.ToString(); } } else if (item.Value.StartsWith("**del.") || item.StringType.Equals("REG_NONE")) { returnValue.Exists = PolicyItem.ITEM_EXISTS_SAME; returnValue.ExistsInfo = "Deleted locally too"; returnValue.LocalValue = ""; } else { returnValue.Exists = PolicyItem.ITEM_MISSING; returnValue.ExistsInfo = "Not set locally"; returnValue.LocalValue = ""; } } catch { returnValue.Exists = PolicyItem.ITEM_MISSING; returnValue.ExistsInfo = "Not set locally"; returnValue.LocalValue = ""; } return(returnValue); }