From 914fb9e4f84a0d802d035ddba0c0d08efd46dd6e Mon Sep 17 00:00:00 2001
From: "Michael H.G. Schmidt" <michael@schmidt2.de>
Date: Mon, 26 Dec 2022 19:04:35 +0100
Subject: [PATCH] improvements

---
 scripts/uninstall-edge.cmd     | 24 +++++++++++++++++-------
 scripts/uninstall-onedrive.cmd | 33 ++++++++++++++++++++-------------
 scripts/uninstall-pchealth.cmd | 22 ++++++++++++++++++----
 tools/reset-firefox.cmd        |  1 +
 4 files changed, 56 insertions(+), 24 deletions(-)

diff --git a/scripts/uninstall-edge.cmd b/scripts/uninstall-edge.cmd
index c7ea673..bb2b2b8 100644
--- a/scripts/uninstall-edge.cmd
+++ b/scripts/uninstall-edge.cmd
@@ -6,14 +6,19 @@ set INSTALLER=Application\84.0.522.52\Installer
 
 echo ####### %0 #######
 
-@echo on
+if NOT exist %EDGEROOT%\%INSTALLER% (
+  echo EDGE browser is NOT installed!
+  echo ####### %0 #######
+  exit /b
+)
+
+echo UNINSTALLING edge browser ...
 %EDGEROOT%\%INSTALLER%\setup.exe --uninstall --system-level --verbose-logging --force-uninstall 2>nul
-@echo off
 
 echo sleep 5 seconds ...
 ping 127.0.0.1 -n 5 >nul 2>&1
 
-echo cleanup ...
+echo CLEANUP ...
 rd /S /Q %EDGEROOT% 2>nul
 rd /S /Q %EDGEUPDATE% 2>nul
 del /F "%PUBLIC%\Desktop\Microsoft Edge.lnk" 2>nul
@@ -22,10 +27,15 @@ del /F "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" 2>nu
 del /F "%USERPROFILE%\Desktop\Microsoft Edge.lnk" 2>nul
 rd /S /Q "%PROGRAMDATA%\Microsoft\EdgeUpdate" 2>nul
 
-echo block edge updates ...
-reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EdgeUpdate" ^
-  /v "DoNotUpdateToEdgeWithChromium" /d 1 /t REG_DWORD /f
+echo REMOVING edge browser update task ...
+powershell -Command "Get-ScheduledTask | Where-Object {$_.Taskname -match 'EdgeUpdate'} | Unregister-ScheduledTask -Confirm:$false"
+
+echo BLOCKING further edge updates ...
+reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EdgeUpdate" ^
+  /v "DoNotUpdateToEdgeWithChromium" /d 1 /t REG_DWORD /f 1>nul 2>&1
+
+echo HIDING edge update in apps list ...
+reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge Update" /v "SystemComponent" /d 1 /t REG_DWORD /f 1>nul 2>&1
 
-echo.
 echo ####### %0 #######
 
diff --git a/scripts/uninstall-onedrive.cmd b/scripts/uninstall-onedrive.cmd
index 0e2dd3d..db0ca20 100644
--- a/scripts/uninstall-onedrive.cmd
+++ b/scripts/uninstall-onedrive.cmd
@@ -1,22 +1,21 @@
 @echo off
 
-set x86=%SYSTEMROOT%\System32\OneDriveSetup.exe
-set x64=%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe
+set OneDrive="%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe"
 
 echo ####### %0 #######
 
-echo KILLING OneDrive ...
+if NOT exist %OneDrive% (
+  echo OneDrive is NOT installed!
+  echo ####### %0 #######
+  exit /b
+)
+
+echo KILLING all OneDrive instances ...
 taskkill /f /im OneDrive.exe > NUL 2>&1
 
-echo sleep 5 seconds ...
-ping 127.0.0.1 -n 5 > NUL 2>&1
-
 echo UNINSTALLING OneDrive ...
-if exist %x64% (
-  %x64% /uninstall 2>nul
-) else (
-  %x86% /uninstall 2>nul
-)
+rem %OneDrive% /uninstall 2>nul
+%OneDrive% /uninstall
 
 echo sleep 5 seconds ...
 ping 127.0.0.1 -n 5 > NUL 2>&1
@@ -27,14 +26,22 @@ rd "C:\OneDriveTemp" /Q /S > NUL 2>&1
 rd "%LOCALAPPDATA%\Microsoft\OneDrive" /Q /S > NUL 2>&1
 rd "%PROGRAMDATA%\Microsoft OneDrive" /Q /S > NUL 2>&1
 
-echo remove OneDrive from explorer ...
+echo removing OneDrive from explorer ...
 reg DELETE "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f > NUL 2>&1
 reg DELETE "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f > NUL 2>&1
 reg DELETE "HKEY_CURRENT_USER\Software\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}\ShellFolder" /f > NUL 2>&1
 reg DELETE "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}\ShellFolder" /f > NUL 2>&1
 
-echo remove OneDrive update task ...
+echo removing OneDrive update task ...
 powershell -Command "Get-ScheduledTask | Where-Object {$_.Taskname -match 'OneDrive Standalone Update'} | Unregister-ScheduledTask -Confirm:$false"
 
+echo KILLING all OneDrive SETUP instances ...
+taskkill /f /im OneDriveSetup.exe > NUL 2>&1
+
+echo removing OneDrive setup exe ...
+setacl -on %OneDrive% -ot file -actn setowner -ownr "n:Administrators" 2>nul
+setacl -on %OneDrive% -ot file -actn ace -ace "n:Administrators;p:full" 2>nul
+del /Y %OneDrive% 2>nul
+
 echo ####### %0 #######
 
diff --git a/scripts/uninstall-pchealth.cmd b/scripts/uninstall-pchealth.cmd
index 43660ec..744a5bc 100644
--- a/scripts/uninstall-pchealth.cmd
+++ b/scripts/uninstall-pchealth.cmd
@@ -2,6 +2,12 @@
 
 echo ####### %0 #######
 
+if NOT exist "%ProgramFiles%\PCHealthCheck\PCHealthCheck.exe" (
+  echo PC health check is NOT installed!
+  echo ####### %0 #######
+  exit /b
+)
+
 echo KILLING PC health check ...
 taskkill /f /im PCHealthCheck.exe > NUL 2>&1
 
@@ -9,14 +15,22 @@ echo DELETING PC health check folder ...
 rd "%ProgramFiles%\PCHealthCheck" /Q /S > NUL 2>&1
 
 echo remove PC health check from application list ...
-reg DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7B1FCD52-8F6B-4F12-A143-361EA39F5E7C}" /f > NUL 2>&1
+reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7B1FCD52-8F6B-4F12-A143-361EA39F5E7C}" /f > NUL 2>&1
+rem ... also the german registry entry ...
+reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B3956CF3-F6C5-4567-AC38-1FD4432B319C}" /f > NUL 2>&1
 
 echo removing PC health check registry keys ...
-reg DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHealthCheck" /f > NUL 2>&1
-reg DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHC" /f > NUL 2>&1
+reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHealthCheck" /f > NUL 2>&1
+reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHC" /f > NUL 2>&1
+
+echo blocking Microsoft reinstall attempts ...
+reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHealthCheck" ^
+  /v "installed" /t REG_DWORD /d 1 /f > NUL 2>&1
+reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHC" ^
+  /v "PreviousUninstall" /t REG_DWORD /d 1 /f > NUL 2>&1
 
 echo removing link in Start menu ...
-del /F "%ProgramData%\Microsoft\Windows\Start Menu\Programs\PC Health Check.lnk"
+del /F "%ProgramData%\Microsoft\Windows\Start Menu\Programs\PC Health Check.lnk" 2>nul
 
 echo ####### %0 #######
 
diff --git a/tools/reset-firefox.cmd b/tools/reset-firefox.cmd
index 0aacc0d..fd9d196 100644
--- a/tools/reset-firefox.cmd
+++ b/tools/reset-firefox.cmd
@@ -7,3 +7,4 @@ echo deleting user profile ...
 deltree %USERPROFILE%\AppData\Local\Mozilla
 deltree %USERPROFILE%\AppData\LocalLow\Mozilla
 deltree %USERPROFILE%\AppData\Roaming\Mozilla
+