From d0d11a82f3b58276ec7ac00211dc2bfbf6ae2757 Mon Sep 17 00:00:00 2001 From: he3als <65787561+he3als@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:12:04 +0100 Subject: [PATCH] fix(Toggle Defender): make uninstalling package not prompt for restart --- .../5. Security/Defender/Toggle Defender.cmd | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/playbook/Executables/Atlas/3. Configuration/5. Security/Defender/Toggle Defender.cmd b/src/playbook/Executables/Atlas/3. Configuration/5. Security/Defender/Toggle Defender.cmd index 13abe8afa7..d803875fa4 100644 --- a/src/playbook/Executables/Atlas/3. Configuration/5. Security/Defender/Toggle Defender.cmd +++ b/src/playbook/Executables/Atlas/3. Configuration/5. Security/Defender/Toggle Defender.cmd @@ -35,6 +35,7 @@ $AtlasPackageName = 'Z-Atlas-NoDefender-Package' $AtlasModules = "$env:windir\AtlasModules" $onlineSxS = "$AtlasModules\Scripts\online-sxs.cmd" $packagesPath = "$AtlasModules\Packages" +$ProgressPreference = 'SilentlyContinue' function PauseNul ($message = "Press any key to exit... ") { Write-Host $message -NoNewLine @@ -53,11 +54,11 @@ function UninstallPackage { } else { foreach ($package in $packages) { try { - Remove-WindowsPackage -Online -PackageName $package *>$null + Remove-WindowsPackage -Online -PackageName $package -NoRestart -LogLevel 1 *>$null } catch { Write-Host "Something went wrong removing the package: $package" -ForegroundColor Red Write-Host "$_`n" -ForegroundColor Red - if ($Enable -or $Disable) {return 1} else {PauseNul; exit 1} + if (!($Enable -or $Disable)) {PauseNul}; exit 1 } } } @@ -70,8 +71,7 @@ function InstallPackage { & $onlineSxS "$latestCabPath" -Silent } catch { Write-Host "`nSomething went wrong whilst adding the Defender package.`nPlease report the error above to the Atlas team." -ForegroundColor Yellow - PauseNul - exit 1 + if (!($Enable -or $Disable)) {PauseNul}; exit 1 } } @@ -132,14 +132,20 @@ function Menu { Write-Host "Are you sure that you want to disable Defender?" -ForegroundColor Red Write-Host "Although disabling Windows Defender will improve performance and convienience, it's important for security.`n" - Pause; Clear-Host; InstallPackage - + Pause + Clear-Host + InstallPackage SetDefenderConfigInRegistry -SetValue $false + Finish } # Enable Defender 2 { - Clear-Host; UninstallPackage; SetDefenderConfigInRegistry -SetValue $true; Finish + Clear-Host + UninstallPackage + SetDefenderConfigInRegistry -SetValue $true + + Finish } default { # Do nothing