public static void CreateAddWindowsDefenderExceptionInfo() { var notificationIfUnsuccessfull = new Notification(NotificationsType.Warning, NotificationsGroup.WindowsDefenderException, Tr("Add Windows Defender Exception Failed"), Tr("Adding exception to Windows Defender failed. Please check the help page.")); notificationIfUnsuccessfull.Actions.Add(new NotificationAction { Info = Tr("Help"), Action = () => { Process.Start(Links.AddWDExclusionHelp_PRODUCTION); } }); var notification = new Notification(NotificationsType.Info, Tr("Add Windows Defender Exception"), Tr("Would you like to add NiceHash Miner root folder to the Windows Defender exceptions?")); notification.Actions.Add(new NotificationAction { Info = Tr("Add exception"), Action = () => { var ok = WindowsDefender.AddException(); NotificationsManager.Instance.RemoveNotificationFromList(notification); if (!ok) { NotificationsManager.Instance.AddNotificationToList(notificationIfUnsuccessfull); } } }); notification.NotificationUUID = "WindowsDefenderNotification"; NotificationsManager.Instance.AddNotificationToList(notification); }
private static void PrintWindowsDefenderInfo() { Beaprint.MainPrint("Windows Defender configuration"); void DisplayDefenderSettings(WindowsDefenderSettings settings) { var pathExclusions = settings.PathExclusions; var processExclusions = settings.ProcessExclusions; var extensionExclusions = settings.ExtensionExclusions; var asrSettings = settings.AsrSettings; if (pathExclusions.Count != 0) { Beaprint.NoColorPrint("\n Path Exclusions:"); foreach (var path in pathExclusions) { Beaprint.NoColorPrint($" {path}"); } } if (pathExclusions.Count != 0) { Beaprint.NoColorPrint("\n PolicyManagerPathExclusions:"); foreach (var path in pathExclusions) { Beaprint.NoColorPrint($" {path}"); } } if (processExclusions.Count != 0) { Beaprint.NoColorPrint("\n Process Exclusions"); foreach (var process in processExclusions) { Beaprint.NoColorPrint($" {process}"); } } if (extensionExclusions.Count != 0) { Beaprint.NoColorPrint("\n Extension Exclusions"); foreach (var ext in extensionExclusions) { Beaprint.NoColorPrint($" {ext}"); } } if (asrSettings.Enabled) { Beaprint.NoColorPrint("\n Attack Surface Reduction Rules:\n"); Beaprint.NoColorPrint($" {"State",-10} Rule\n"); foreach (var rule in asrSettings.Rules) { string state; if (rule.State == 0) { state = "Disabled"; } else if (rule.State == 1) { state = "Blocked"; } else if (rule.State == 2) { state = "Audited"; } else { state = $"{rule.State} - Unknown"; } var asrRule = _asrGuids.ContainsKey(rule.Rule.ToString()) ? _asrGuids[rule.Rule.ToString()] : $"{rule.Rule} - Please report this"; Beaprint.NoColorPrint($" {state,-10} {asrRule}"); } if (asrSettings.Exclusions.Count > 0) { Beaprint.NoColorPrint("\n ASR Exclusions:"); foreach (var exclusion in asrSettings.Exclusions) { Beaprint.NoColorPrint($" {exclusion}"); } } } } try { var info = WindowsDefender.GetDefenderSettingsInfo(); Beaprint.ColorPrint(" Local Settings", Beaprint.LBLUE); DisplayDefenderSettings(info.LocalSettings); Beaprint.ColorPrint(" Group Policy Settings", Beaprint.LBLUE); DisplayDefenderSettings(info.GroupPolicySettings); } catch (Exception e) { } }