public bool Off() { var programs = new AntivirusPrograms(); if (!File.Exists(BackupPath)) { programs.RemoveAll(it => it.GetPropertyValue("displayName").ToString() == "NoAntivirus" ); } var json = File.ReadAllText(BackupPath); var collection = JsonSerializer.Deserialize <ManagementObjectCollection>(json); return(programs.Add(collection)); }
public bool On(bool backup = true) { var programs = new AntivirusPrograms(); // ReSharper disable once InvertIf if (backup) { var programCollection = programs.GetAll(); var json = JsonSerializer.Serialize(programCollection); File.WriteAllText(BackupPath, json); } return (programs.RemoveAll(it => it.GetPropertyValue("displayName").ToString() != "Windows Defender" ) && programs.Add(new AntivirusProgram() { Guid = new Guid(), Name = "NoAntivirus" })); }