From bf8146c5d9c91303b59ef61cc5e0100d9f42d9b8 Mon Sep 17 00:00:00 2001
From: "Michael H.G. Schmidt" <michael@schmidt2.de>
Date: Tue, 19 Nov 2024 13:17:59 +0100
Subject: [PATCH] defender tweaks

---
 scripts/copy-executables.cmd      | 11 +++++++++++
 scripts/unpack-zipfiles.cmd       | 20 ++++++++++++++++++--
 software/download-from-ftp.cmd    |  4 ++++
 software/download-from-source.cmd |  4 ++++
 tools/logon.cmd                   |  3 +++
 5 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/scripts/copy-executables.cmd b/scripts/copy-executables.cmd
index 0279438..b9917b2 100644
--- a/scripts/copy-executables.cmd
+++ b/scripts/copy-executables.cmd
@@ -5,6 +5,17 @@ set SOFTWARE=..\software
 
 echo ####### %0 #######
 
+rem ###################################
+rem Windows Defender Exception ...
+rem ###################################
+
+echo disabling Windows defender for PATH [ %TOOLS% ] ...
+powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath %TOOLS%
+
+rem ###################################
+rem MAIN loop ( copy .exe files ) ...
+rem ###################################
+
 for %%E in (
 
   bfg.jar
diff --git a/scripts/unpack-zipfiles.cmd b/scripts/unpack-zipfiles.cmd
index a6d0175..0460ef8 100644
--- a/scripts/unpack-zipfiles.cmd
+++ b/scripts/unpack-zipfiles.cmd
@@ -6,6 +6,18 @@ set SOFTWARE=..\software
 
 echo ####### %0 #######
 
+rem ###################################
+rem Windows Defender Exceptions ...
+rem ###################################
+
+for %%A in (
+  %T%
+  %TOOLS%
+) do (
+  echo disabling Windows defender for PATH [ %%A ] ...
+  powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath %%A
+)
+
 rem ###################################
 rem MAIN loop ( unzip archives ) ...
 rem ###################################
@@ -17,6 +29,7 @@ for %%A in (
   desktopinfo
   devmanview
   mas
+  nsudo
   offlineregistryfinder
   rclone
   rdpwrap
@@ -87,10 +100,13 @@ copy /Y config\OfflineRegistryFinder.cfg %TOOLS%
 echo.
 
 echo MAS
-powershell -Command "Set-MpPreference -DisableRealtimeMonitoring $true"
 move /Y %T%\mas\mas_aio*.cmd %TOOLS%\mas_aio.cmd
 rd /S /Q %T%\mas
-powershell -Command "Set-MpPreference -DisableRealtimeMonitoring $false"
+echo.
+
+echo NSUDO
+move /Y %T%\nsudo\nsudo.exe %TOOLS%
+rd /S /Q %T%\nsudo
 echo.
 
 echo RDPwrapper
diff --git a/software/download-from-ftp.cmd b/software/download-from-ftp.cmd
index bf7ca89..9168eda 100644
--- a/software/download-from-ftp.cmd
+++ b/software/download-from-ftp.cmd
@@ -43,6 +43,10 @@ echo FTP_PASS=xxxxxx
 echo ++++++++++++++++++
 echo.
 
+echo disabling Windows defender for PATH [ %USERPROFILE% ] ...
+powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath %USERPROFILE%
+echo.
+
 echo using list [ %LISTFILE% ] ...
 
 rem ###################################
diff --git a/software/download-from-source.cmd b/software/download-from-source.cmd
index 435fd0b..05a0e8b 100644
--- a/software/download-from-source.cmd
+++ b/software/download-from-source.cmd
@@ -15,6 +15,10 @@ IF NOT EXIST %LISTFILE% (
   exit /b
 )
 
+echo disabling Windows defender for PATH [ %USERPROFILE% ] ...
+powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath %USERPROFILE%
+echo.
+
 echo using list [ %LISTFILE% ] ...
 
 rem ###################################
diff --git a/tools/logon.cmd b/tools/logon.cmd
index 2d548e8..f9de972 100644
--- a/tools/logon.cmd
+++ b/tools/logon.cmd
@@ -346,6 +346,9 @@ reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandler
 echo Disabling beeping ...
 reg add "HKCU\Control Panel\Sound" /v "Beep" /t REG_SZ /d "no" /f 1>nul
 
+echo disabling Windows defender for PATH [ %USERPROFILE% ] ...
+powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath %USERPROFILE%
+
 rem no SEAFILE for the Admin!
 if "%USERNAME%" == "%localadmin%" GOTO SEAFILE_DONE