diff --git a/lib/commands/security_command.dart b/lib/commands/security_command.dart index 6d5c7cf..690e38e 100644 --- a/lib/commands/security_command.dart +++ b/lib/commands/security_command.dart @@ -91,8 +91,8 @@ Virus and Threat Protections Status: ${_securityService.statusDefenderProtection try { await _securityService.disableDefender(); - } catch (e) { - stderr.writeln('$tag Error disabling Windows Defender: $e'); + } on Exception catch (e) { + stderr.writeln('$tag Error disabling Windows Defender: ${e.toString()}'); exit(1); } } diff --git a/lib/services/security_service.dart b/lib/services/security_service.dart index 24c66a2..c0f0e82 100644 --- a/lib/services/security_service.dart +++ b/lib/services/security_service.dart @@ -244,41 +244,48 @@ class SecurityService implements SetupService { } Future disableDefender() async { - await _winPackageService.downloadPackage(WinPackageType.defenderRemoval); + try { + await _winPackageService.downloadPackage(WinPackageType.defenderRemoval); - RegistryUtilsService.writeDword( - Registry.localMachine, - r'SOFTWARE\Policies\Microsoft\Windows Defender', - 'DisableAntiSpyware', - 1); - RegistryUtilsService.writeDword(Registry.localMachine, - r'SOFTWARE\Policies\Microsoft\Windows Defender', 'DisableAntiVirus', 1); - RegistryUtilsService.writeDword( - Registry.localMachine, - r'SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection', - 'DisableRealtimeMonitoring', - 1); + RegistryUtilsService.writeDword( + Registry.localMachine, + r'SOFTWARE\Policies\Microsoft\Windows Defender', + 'DisableAntiSpyware', + 1); + RegistryUtilsService.writeDword( + Registry.localMachine, + r'SOFTWARE\Policies\Microsoft\Windows Defender', + 'DisableAntiVirus', + 1); + RegistryUtilsService.writeDword( + Registry.localMachine, + r'SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection', + 'DisableRealtimeMonitoring', + 1); - await _shell.run( - 'start /WAIT /MIN /B "" "%systemroot%\\System32\\gpupdate.exe" /Target:Computer /Force'); + await _shell.run( + 'start /WAIT /MIN /B "" "%systemroot%\\System32\\gpupdate.exe" /Target:Computer /Force'); - await _shell.run( - "PowerShell -EP Unrestricted -NonInteractive -NoLogo -NoP -C 'Start-Process -FilePath \"$_mpCmdRunString\" -ArgumentList \"-RemoveDefinitions -All\" -NoNewWindow -Wait'"); + await _shell.run( + "PowerShell -EP Unrestricted -NonInteractive -NoLogo -NoP -C 'Start-Process -FilePath \"$_mpCmdRunString\" -ArgumentList \"-RemoveDefinitions -All\" -NoNewWindow -Wait'"); - await _shell.run( - '"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\SOFTWARE\\Microsoft\\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f'); - await _shell.run( - '"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\SOFTWARE\\Microsoft\\Windows Defender" /v DisableAntiVirus /t REG_DWORD /d 1 /f'); + await _shell.run( + '"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\SOFTWARE\\Microsoft\\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f'); + await _shell.run( + '"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\SOFTWARE\\Microsoft\\Windows Defender" /v DisableAntiVirus /t REG_DWORD /d 1 /f'); - await _shell.run( - '"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\System\\ControlSet001\\Services\\MDCoreSvc" /v Start /t REG_DWORD /d 4 /f'); + await _shell.run( + '"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\System\\ControlSet001\\Services\\MDCoreSvc" /v Start /t REG_DWORD /d 4 /f'); - RegistryUtilsService.deleteValue( - Registry.localMachine, - r'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce', - 'RevisionEnableDefenderCMD'); + RegistryUtilsService.deleteValue( + Registry.localMachine, + r'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce', + 'RevisionEnableDefenderCMD'); - await _winPackageService.installPackage(WinPackageType.defenderRemoval); + await _winPackageService.installPackage(WinPackageType.defenderRemoval); + } on Exception catch (e) { + throw ('Failed to disable Windows Defender:\n\n$e'); + } } bool get statusUAC { diff --git a/pubspec.lock b/pubspec.lock index f22d148..1328078 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -26,10 +26,10 @@ packages: dependency: transitive description: name: ansicolor - sha256: "8bf17a8ff6ea17499e40a2d2542c2f481cd7615760c6d34065cb22bfd22e6880" + sha256: "50e982d500bc863e1d703448afdbf9e5a72eb48840a4f766fa361ffd6877055f" url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.0.3" args: dependency: "direct main" description: @@ -170,10 +170,10 @@ packages: dependency: transitive description: name: crypto - sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27 url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" dart_style: dependency: transitive description: @@ -186,18 +186,18 @@ packages: dependency: "direct main" description: name: dio - sha256: e17f6b3097b8c51b72c74c9f071a605c47bcc8893839bd66732457a5ebe73714 + sha256: "0dfb6b6a1979dac1c1245e17cef824d7b452ea29bd33d3467269f9bef3715fb0" url: "https://pub.dev" source: hosted - version: "5.5.0+1" + version: "5.6.0" dio_web_adapter: dependency: transitive description: name: dio_web_adapter - sha256: "36c5b2d79eb17cdae41e974b7a8284fec631651d2a6f39a8a2ff22327e90aeac" + sha256: "33259a9276d6cea88774a0000cfae0d861003497755969c92faa223108620dc8" url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "2.0.0" fake_async: dependency: transitive description: @@ -210,10 +210,10 @@ packages: dependency: "direct main" description: name: ffi - sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" + sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" file: dependency: transitive description: @@ -542,10 +542,10 @@ packages: dependency: transitive description: name: path_provider_android - sha256: "490539678396d4c3c0b06efdaab75ae60675c3e0c66f72bc04c2e2c1e0e2abeb" + sha256: "6f01f8e37ec30b07bc424b4deabac37cacb1bc7e2e515ad74486039918a37eb7" url: "https://pub.dev" source: hosted - version: "2.2.9" + version: "2.2.10" path_provider_foundation: dependency: transitive description: @@ -614,10 +614,10 @@ packages: dependency: "direct main" description: name: process_run - sha256: c917dfb5f7afad4c7485bc00a4df038621248fce046105020cea276d1a87c820 + sha256: "112a77da35be50617ed9e2230df68d0817972f225e7f97ce8336f76b4e601606" url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" provider: dependency: "direct main" description: @@ -747,26 +747,26 @@ packages: dependency: transitive description: name: synchronized - sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" + sha256: a824e842b8a054f91a728b783c177c1e4731f6b124f9192468457a8913371255 url: "https://pub.dev" source: hosted - version: "3.1.0+1" + version: "3.2.0" system_theme: dependency: "direct main" description: name: system_theme - sha256: a32db6caa3a5129d02c03443121662959fba7ec1a8b01c78ee9a42718fbb3ef6 + sha256: "676f8e5bdbf17d5b1267592370810df8cdfaa01d3a2e121b22bd4ea30e63f17c" url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.1.0" system_theme_web: dependency: transitive description: name: system_theme_web - sha256: "7566f5a928f6d28d7a60c97bea8a851d1c6bc9b86a4df2366230a97458489219" + sha256: "900c92c5c050ce58048f241ef9a17e5cd8629808325a05b473dc62a6e99bae77" url: "https://pub.dev" source: hosted - version: "0.0.2" + version: "0.0.3" term_glyph: dependency: transitive description: @@ -811,10 +811,10 @@ packages: dependency: transitive description: name: vm_service - sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.4" + version: "14.2.5" watcher: dependency: transitive description: @@ -851,10 +851,10 @@ packages: dependency: "direct main" description: name: win32 - sha256: "015002c060f1ae9f41a818f2d5640389cc05283e368be19dc8d77cecb43c40c9" + sha256: "68d1e89a91ed61ad9c370f9f8b6effed9ae5e0ede22a270bdfa6daf79fc2290a" url: "https://pub.dev" source: hosted - version: "5.5.3" + version: "5.5.4" win32_registry: dependency: "direct main" description: @@ -897,5 +897,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.5.0-259.0.dev <4.0.0" + dart: ">=3.5.0 <4.0.0" flutter: ">=3.22.0"