|
|
用AI写的,自己试了没什么问题,不保证质量,不喜勿喷:
- @echo off
- chcp 936 >nul 2>nul
- setlocal EnableExtensions
- title 离线删除[Windows Defender ^& OneDrive]
- set "ESC="
- for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
- if defined ESC if "%ESC%"=="$E" set "ESC="
- if not defined ESC (
- for /F "delims=" %%a in ('powershell -NoProfile -Command "[char]27"') do set "ESC=%%a"
- )
- set "TARGET="
- set "REG=%SystemRoot%\System32\reg.exe"
- set "TAKEOWN=%SystemRoot%\System32\takeown.exe"
- set "ICACLS=%SystemRoot%\System32\icacls.exe"
- set "FINDSTR=%SystemRoot%\System32\findstr.exe"
- set "FIND=%SystemRoot%\System32\find.exe"
- set "DISM=%SystemRoot%\System32\dism.exe"
- set "TMPDIR=%TEMP%"
- if not defined TMPDIR set "TMPDIR=%SystemRoot%\Temp"
- if not exist "%TMPDIR%" md "%TMPDIR%" >nul 2>nul
- if not exist "%TMPDIR%" set "TMPDIR=%SystemRoot%"
- if not "%TMPDIR:~3%"=="" if "%TMPDIR:~-1%"=="\" set "TMPDIR=%TMPDIR:~0,-1%"
- echo ================================================================
- echo 离线删除[Windows Defender ^& OneDrive]
- echo ================================================================
- if not "%~1"=="" goto :manual
- set "RETRY=0"
- :auto_scan
- set "TARGET="
- echo [自动] 正在扫描包含 Windows 安装的分区 ...
- for %%D in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
- if not "%%D"=="%SystemDrive:~0,1%" (
- if exist "%%D:\Windows\System32\config\SOFTWARE" (
- if not defined TARGET (
- set "TARGET=%%D"
- echo [找到] %%D:\
- )
- )
- )
- )
- if defined TARGET goto :verify
- set /a RETRY+=1
- if %RETRY% lss 5 (
- echo [警告] 未找到目标分区,%RETRY%/5 次重试...
- ping -n 3 127.0.0.1 >nul 2>nul
- goto :auto_scan
- )
- echo [错误] 多次扫描未找到目标分区。
- echo 请手动输入目标分区盘符(例如 C 或 C:),或按 Ctrl+C 退出。
- set "TARGET="
- set /p TARGET=目标分区:
- if not defined TARGET goto :done
- set "TARGET=%TARGET::=%"
- set "TARGET=%TARGET:\=%"
- if not defined TARGET goto :done
- if not "%TARGET:~1,1%"=="" goto :bad_target
- if /i "%TARGET%"=="%SystemDrive:~0,1%" goto :pe_self
- goto :verify
- :manual
- set "TARGET=%~1"
- set "TARGET=%TARGET::=%"
- set "TARGET=%TARGET:\=%"
- if not defined TARGET (
- echo [错误] 未指定目标分区。
- goto :done
- )
- if not "%TARGET:~1,1%"=="" goto :bad_target
- if /i "%TARGET%"=="%SystemDrive:~0,1%" goto :pe_self
- :verify
- if not exist "%TARGET%:\Windows\System32\config\SOFTWARE" (
- echo [错误] %TARGET%:\ 不是有效的 Windows 分区。
- goto :done
- )
- echo ================================================================
- echo 目标: %TARGET%:\
- echo ================================================================
- if not exist "%REG%" copy /y "%TARGET%:\Windows\System32\reg.exe" "%SystemRoot%\System32\" >nul 2>nul
- if not exist "%REG%" (
- ping -n 3 127.0.0.1 >nul 2>nul
- copy /y "%TARGET%:\Windows\System32\reg.exe" "%SystemRoot%\System32\" >nul 2>nul
- )
- if not exist "%REG%" (
- echo [错误] reg.exe 不可用,无法继续。
- goto :done
- )
- if not exist "%TAKEOWN%" copy /y "%TARGET%:\Windows\System32\takeown.exe" "%SystemRoot%\System32\" >nul 2>nul
- if not exist "%ICACLS%" copy /y "%TARGET%:\Windows\System32\icacls.exe" "%SystemRoot%\System32\" >nul 2>nul
- if not exist "%FINDSTR%" copy /y "%TARGET%:\Windows\System32\findstr.exe" "%SystemRoot%\System32\" >nul 2>nul
- if not exist "%FIND%" copy /y "%TARGET%:\Windows\System32\find.exe" "%SystemRoot%\System32\" >nul 2>nul
- if not exist "%DISM%" copy /y "%TARGET%:\Windows\System32\dism.exe" "%SystemRoot%\System32\" >nul 2>nul
- echo.
- echo ================================================================
- echo [1/2] 删除 Windows Defender
- echo ================================================================
- set /a PROG_CUR=0
- set /a PROG_MAX=12
- set "PROG_FIRST=1"
- call :draw_progress
- call :safe_rmdir "%TARGET%:\Program Files\Windows Defender"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\Program Files (x86)\Windows Defender"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\Program Files\Windows Defender Advanced Threat Protection"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\ProgramData\Microsoft\Windows Defender"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\ProgramData\Microsoft\Windows Security Health"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\Windows\System32\Tasks\Microsoft\Windows\Windows Defender"
- set /a PROG_CUR+=1
- call :draw_progress
- call :clean_taskcache "Windows Defender"
- set /a PROG_CUR+=1
- call :draw_progress
- call :disable_defender_services
- set /a PROG_CUR+=1
- call :draw_progress
- call :write_defender_policies
- set /a PROG_CUR+=1
- call :draw_progress
- call :remove_sechealth_advanced
- set /a PROG_CUR+=1
- call :draw_progress
- call :hide_spv_all_users
- set /a PROG_CUR+=1
- call :draw_progress
- echo ================================================================
- echo [1/2] Windows Defender 清理完成
- echo ================================================================
- echo.
- echo ================================================================
- echo [2/2] 删除 OneDrive
- echo ================================================================
- set /a PROG_CUR=0
- set /a PROG_MAX=11
- set "PROG_FIRST=1"
- call :draw_progress
- call :remove_onedrive_appx
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_delete "%TARGET%:\Windows\System32\OneDriveSetup.exe"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_delete "%TARGET%:\Windows\SysWOW64\OneDriveSetup.exe"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\ProgramData\Microsoft OneDrive"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\Windows\System32\Tasks\Microsoft\OneDrive"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\Windows\System32\Tasks\Microsoft\Windows\OneDrive"
- set /a PROG_CUR+=1
- call :draw_progress
- call :clean_taskcache "OneDrive"
- set /a PROG_CUR+=1
- call :draw_progress
- call :safe_rmdir "%TARGET%:\OneDrive"
- set /a PROG_CUR+=1
- call :draw_progress
- for /d %%U in ("%TARGET%:\Users\*") do call :clean_user_onedrive_files "%%~nxU"
- set /a PROG_CUR+=1
- call :draw_progress
- call :write_onedrive_policies
- set /a PROG_CUR+=1
- call :draw_progress
- call :clean_default_user_onedrive
- for /d %%U in ("%TARGET%:\Users\*") do call :clean_one_user_onedrive "%%~nxU"
- set /a PROG_CUR+=1
- call :draw_progress
- echo ================================================================
- echo [2/2] OneDrive 清理完成
- echo ================================================================
- echo.
- goto :done
- :draw_progress
- setlocal EnableDelayedExpansion
- set /a PCT=%PROG_CUR%*100/%PROG_MAX%
- set /a FILL=%PCT%*30/100
- set "BAR="
- for /l %%i in (1,1,30) do (
- if %%i leq %FILL% (set "BAR=!BAR!#") else (set "BAR=!BAR!-")
- )
- if not defined ESC (
- echo 进度: [!BAR!] !PCT!%%
- endlocal
- goto :eof
- )
- if "!PROG_FIRST!"=="1" (
- <nul set /p "= 进度: [!BAR!] !PCT!%%"
- echo.
- endlocal
- set "PROG_FIRST=0"
- goto :eof
- )
- <nul set /p "=%ESC%[1A%ESC%[2K 进度: [!BAR!] !PCT!%%"
- echo.
- endlocal
- goto :eof
- :get_filter
- set "FLT=%FINDSTR%"
- if exist "%FLT%" goto :eof
- set "FLT=%FIND%"
- if exist "%FLT%" goto :eof
- set "FLT="
- goto :eof
- :is_special_user
- if /i "%~1"=="Default" exit /b 1
- if /i "%~1"=="Public" exit /b 1
- if /i "%~1"=="All Users" exit /b 1
- if /i "%~1"=="Default User" exit /b 1
- exit /b 0
- :safe_rmdir
- set "DIR=%~1"
- if not defined DIR goto :eof
- if not exist "%DIR%" goto :eof
- if exist "%TAKEOWN%" "%TAKEOWN%" /f "%DIR%" /r /d y >nul 2>nul
- if exist "%ICACLS%" "%ICACLS%" "%DIR%" /grant *S-1-5-32-544:F /t /c >nul 2>nul
- rd /s /q "%DIR%" >nul 2>nul
- goto :eof
- :safe_delete
- set "FILE=%~1"
- if not defined FILE goto :eof
- if not exist "%FILE%" goto :eof
- if exist "%TAKEOWN%" "%TAKEOWN%" /f "%FILE%" /a >nul 2>nul
- if exist "%ICACLS%" "%ICACLS%" "%FILE%" /grant *S-1-5-32-544:F >nul 2>nul
- del /f /q "%FILE%" >nul 2>nul
- goto :eof
- :disable_defender_services
- set "SYS_HIVE=%TARGET%:\Windows\System32\config\SYSTEM"
- "%REG%" load HKLM\OFF_SYS "%SYS_HIVE%" >nul 2>nul
- if not errorlevel 1 goto sys_loaded
- goto :eof
- :sys_loaded
- set "CSLIST=ControlSet001 ControlSet002 ControlSet003"
- set "CURN="
- call :get_filter
- if defined FLT (
- for /f "tokens=3" %%N in ('"%REG%" query "HKLM\OFF_SYS\Select" /v Current 2^>nul ^| "%FLT%" /i "Current" 2^>nul') do set "CURN=%%N"
- )
- if defined CURN call :add_current_cs "%CURN%"
- for %%C in (%CSLIST%) do (
- "%REG%" query "HKLM\OFF_SYS\%%C" >nul 2>nul
- if not errorlevel 1 (
- for %%S in (WinDefend WdNisSvc Sense WdBoot WdFilter WdNisDrv MDCoreSvc SecurityHealthService wscsvc SgrmBroker webthreatdefsvc webthreatdefusersvc) do call :set_service_disabled "%%S" "%%C"
- )
- )
- call :unload_hive "HKLM\OFF_SYS"
- goto :eof
- :add_current_cs
- set "CUR=%~1"
- set /a NUM=%CUR% >nul 2>nul
- if not defined NUM goto :eof
- if %NUM% lss 1 goto :eof
- if %NUM% gtr 999 goto :eof
- set "PAD=00%NUM%"
- set "PAD=%PAD:~-3%"
- set "CSC=ControlSet%PAD%"
- set "HIT="
- for %%Q in (%CSLIST%) do if /i "%%Q"=="%CSC%" set "HIT=1"
- if defined HIT goto :eof
- set "CSLIST=%CSLIST% %CSC%"
- goto :eof
- :set_service_disabled
- set "SVC=%~1"
- set "CS=%~2"
- "%REG%" query "HKLM\OFF_SYS\%CS%\Services\%SVC%" >nul 2>nul
- if not errorlevel 1 goto svc_found
- goto :eof
- :svc_found
- "%REG%" add "HKLM\OFF_SYS\%CS%\Services\%SVC%" /v Start /t REG_DWORD /d 4 /f >nul 2>nul
- goto :eof
- :clean_taskcache
- set "TCKEYWORD=%~1"
- if not defined TCKEYWORD goto :eof
- call :get_filter
- if defined FLT goto tc_filter_ok
- goto :eof
- :tc_filter_ok
- set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
- "%REG%" load HKLM\OFF_TC "%SOFT_HIVE%" >nul 2>nul
- if not errorlevel 1 goto tc_loaded
- goto :eof
- :tc_loaded
- set "TCROOT=HKLM\OFF_TC\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache"
- "%REG%" delete "%TCROOT%\Tree\Microsoft\Windows\%TCKEYWORD%" /f >nul 2>nul
- "%REG%" delete "%TCROOT%\Tree\Microsoft\%TCKEYWORD%" /f >nul 2>nul
- set "TCLIST="
- for /f "tokens=*" %%K in ('"%REG%" query "%TCROOT%\Tasks" 2^>nul ^| "%FLT%" /i "{" 2^>nul') do call :tc_collect "%TCROOT%\Tasks\%%K"
- if defined TCLIST for %%K in (%TCLIST%) do call :taskcache_prune "%%K"
- call :unload_hive "HKLM\OFF_TC"
- goto :eof
- :tc_collect
- set "TKEY=%~1"
- if /i not "%TKEY:~0,5%"=="HKLM\" if /i not "%TKEY:~0,5%"=="HKEY_" goto :eof
- set "TCLIST=%TCLIST% %TKEY%"
- goto :eof
- :taskcache_prune
- set "TKEY=%~1"
- set "TPATH="
- for /f "tokens=2,*" %%A in ('"%REG%" query "%TKEY%" /v Path 2^>nul ^| "%FLT%" /i "Path" 2^>nul') do set "TPATH=%%B"
- if not defined TPATH goto :eof
- if /i "%FLT%"=="%FINDSTR%" (set "TCPAT=/i /c:") else (set "TCPAT=/i ")
- setlocal EnableDelayedExpansion
- echo(!TPATH!|"%FLT%" %TCPAT%"%TCKEYWORD%" >nul 2>nul
- if errorlevel 1 (
- endlocal
- goto :eof
- )
- endlocal
- "%REG%" delete "%TKEY%" /f >nul 2>nul
- goto :eof
- :write_defender_policies
- set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
- "%REG%" load HKLM\OFF_SOFT "%SOFT_HIVE%" >nul 2>nul
- if not errorlevel 1 goto def_pol_ok
- goto :eof
- :def_pol_ok
- "%REG%" add "HKLM\OFF_SOFT\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f >nul 2>nul
- "%REG%" add "HKLM\OFF_SOFT\Policies\Microsoft\Windows Defender" /v DisableAntiVirus /t REG_DWORD /d 1 /f >nul 2>nul
- "%REG%" add "HKLM\OFF_SOFT\Policies\Microsoft\Windows Defender" /v ServiceKeepAlive /t REG_DWORD /d 0 /f >nul 2>nul
- "%REG%" add "HKLM\OFF_SOFT\Policies\Microsoft\Windows Defender\Real-Time Protection" /v DisableRealtimeMonitoring /t REG_DWORD /d 1 /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT\Microsoft\Windows\CurrentVersion\Run" /v SecurityHealth /f >nul 2>nul
- call :unload_hive "HKLM\OFF_SOFT"
- goto :eof
- :remove_sechealth_advanced
- set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
- "%REG%" load HKLM\OFF_SOFT2 "%SOFT_HIVE%" >nul 2>nul
- if not errorlevel 1 goto sec_ok
- goto :eof
- :sec_ok
- set "APPXROOT=HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore"
- set "DEPROV=%APPXROOT%\Deprovisioned"
- set "ENDOFLIFE=%APPXROOT%\EndOfLife"
- set "DEADEND=%APPXROOT%\Deleted\EndOfLife"
- call :purge_sec_entries "%APPXROOT%\Staged"
- call :purge_sec_entries "%APPXROOT%\InboxApplications"
- call :purge_sec_entries "%APPXROOT%\Applications"
- call :purge_sec_user_stores
- "%REG%" delete "HKLM\OFF_SOFT2\Classes\AppUserModelId\Windows.Defender" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Classes\AppUserModelId\Microsoft.Windows.Defender" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Classes\WindowsDefender" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Explorer\ShellServiceObjects\{900c0763-5cad-4a34-bc1f-40cd513679d5}" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\ShellServiceObjects\{900c0763-5cad-4a34-bc1f-40cd513679d5}" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Run" /v "SecurityHealth" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Run" /v "WindowsDefender" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" /v "SecurityHealth" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" /v "Windows Defender" /f >nul 2>nul
- for %%i in (
- 2781761E-28E0-4109-99FE-B9D127C57AFE
- 2781761E-28E2-4109-99FE-B9D127C57AFE
- 195B4D07-3DE2-4744-BBF2-D90121AE785B
- 361290c0-cb1b-49ae-9f3e-ba1cbe5dab35
- 45F2C32F-ED16-4C94-8493-D72EF93A051B
- 6CED0DAA-4CDE-49C9-BA3A-AE163DC3D7AF
- 8a696d12-576b-422e-9712-01b9dd84b446
- 8C9C0DB7-2CBA-40F1-AFE0-C55740DD91A0
- A2D75874-6750-4931-94C1-C99D3BC9D0C7
- A7C452EF-8E9F-42EB-9F2B-245613CA0DC9
- DACA056E-216A-4FD1-84A6-C306A017ECEC
- E3C9166D-1D39-4D4E-A45D-BC7BE9B00578
- F6976CF5-68A8-436C-975A-40BE53616D59
- E48B2549-D510-4A76-8A5F-FC126A6215F0
- ) do (
- "%REG%" delete "HKLM\OFF_SOFT2\Classes\CLSID\{%%i}" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Classes\WOW6432Node\CLSID\{%%i}" /f >nul 2>nul
- )
- "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows Security Health" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Classes\CLSID\{BB64F8A7-BEE7-4E1A-AB8D-7D8273F7FDB6}" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{BB64F8A7-BEE7-4E1A-AB8D-7D8273F7FDB6}" /f >nul 2>nul
- call :unload_hive "HKLM\OFF_SOFT2"
- if exist "%DISM%" (
- powershell -NoProfile -ExecutionPolicy Bypass -Command "Import-Module Dism -ErrorAction SilentlyContinue; Get-AppxProvisionedPackage -Path '%TARGET%:\' | Where-Object {$_.PackageName -like '*SecHealthUI*'} | ForEach-Object { Set-NonRemovableAppsPolicy -Path '%TARGET%:\' -PackageFamilyName $_.PackageFamilyName -NonRemovable 0 -ErrorAction SilentlyContinue; Remove-AppxProvisionedPackage -Path '%TARGET%:\' -PackageName $_.PackageName -ErrorAction SilentlyContinue }" >nul 2>nul
- )
- for %%F in (
- "%TARGET%:\Windows\System32\SecurityHealthSystray.exe"
- "%TARGET%:\Windows\System32\SecurityHealthService.exe"
- "%TARGET%:\Windows\System32\SecurityHealthHost.exe"
- "%TARGET%:\Windows\System32\SecurityHealthProxyStub.dll"
- "%TARGET%:\Windows\System32\SecurityHealthCore.dll"
- "%TARGET%:\Windows\System32\SecurityHealthSsoUdk.dll"
- "%TARGET%:\Windows\System32\SecurityHealthSSO.dll"
- "%TARGET%:\Windows\System32\SecurityHealthUdk.dll"
- "%TARGET%:\Windows\System32\SecurityHealthAgent.dll"
- "%TARGET%:\Windows\System32\SecurityAndMaintenance.png"
- "%TARGET%:\Windows\System32\SecurityAndMaintenance_Error.png"
- "%TARGET%:\Windows\SysWOW64\SecurityHealthSystray.exe"
- "%TARGET%:\Windows\SysWOW64\SecurityHealthService.exe"
- ) do call :safe_delete "%%~F"
- for /d %%D in ("%TARGET%:\Windows\SystemApps\Microsoft.Windows.SecHealthUI*") do call :safe_rmdir "%%~fD"
- for /d %%D in ("%TARGET%:\Windows\SystemApps\Microsoft.SecHealthUI*") do call :safe_rmdir "%%~fD"
- for /d %%D in ("%TARGET%:\Program Files\WindowsApps\Microsoft.SecHealthUI*") do call :safe_rmdir "%%~fD"
- for /d %%D in ("%TARGET%:\Windows\System32\SecurityHealth*") do call :safe_rmdir "%%~fD"
- goto :eof
- :purge_sec_user_stores
- call :get_filter
- if not defined FLT goto :eof
- for /f "tokens=*" %%K in ('"%REG%" query "%APPXROOT%" 2^>nul ^| "%FLT%" /i "S-1-5-" 2^>nul') do call :purge_sec_entries "%APPXROOT%\%%K" "%%K"
- goto :eof
- :purge_sec_entries
- set "ROOT=%~1"
- set "SECUSER=%~2"
- call :get_filter
- if defined FLT goto pur_have_filter
- goto :eof
- :pur_have_filter
- set "SECLIST="
- for /f "tokens=*" %%K in ('"%REG%" query "%ROOT%" 2^>nul ^| "%FLT%" /i "SecHealthUI" 2^>nul') do call :purge_sec_collect "%ROOT%\%%K"
- if defined SECLIST for %%K in (%SECLIST%) do call :purge_sec_one "%%K" "%SECUSER%"
- goto :eof
- :purge_sec_collect
- set "SKEY=%~1"
- if /i not "%SKEY:~0,5%"=="HKLM\" if /i not "%SKEY:~0,5%"=="HKEY_" goto :eof
- set "SECLIST=%SECLIST% %SKEY%"
- goto :eof
- :purge_sec_one
- set "SKEY=%~1"
- set "SPKG=%~nx1"
- set "SUSR=%~2"
- "%REG%" add "%DEPROV%\%SPKG%" /f >nul 2>nul
- if defined SUSR (
- "%REG%" add "%ENDOFLIFE%\%SUSR%\%SPKG%" /f >nul 2>nul
- "%REG%" add "%DEADEND%\%SUSR%\%SPKG%" /f >nul 2>nul
- ) else (
- "%REG%" add "%ENDOFLIFE%\%SPKG%" /f >nul 2>nul
- )
- "%REG%" delete "%SKEY%" /f >nul 2>nul
- goto :eof
- :hide_spv_all_users
- set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
- "%REG%" load HKLM\OFF_SPV "%SOFT_HIVE%" >nul 2>nul
- if not errorlevel 1 goto spv_machine_ok
- goto spv_default
- :spv_machine_ok
- call :merge_spv "HKLM\OFF_SPV\Microsoft\Windows\CurrentVersion\Policies\Explorer" "windowsdefender"
- call :unload_hive "HKLM\OFF_SPV"
- :spv_default
- if not exist "%TARGET%:\Users\Default\NTUSER.DAT" goto spv_users
- "%REG%" load HKU\DEF_SPV "%TARGET%:\Users\Default\NTUSER.DAT" >nul 2>nul
- if not errorlevel 1 goto spv_def_ok
- goto spv_users
- :spv_def_ok
- call :merge_spv "HKU\DEF_SPV\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" "windowsdefender"
- call :unload_hive "HKU\DEF_SPV"
- :spv_users
- for /d %%U in ("%TARGET%:\Users\*") do call :hide_spv_one_user "%%~nxU"
- goto :eof
- :hide_spv_one_user
- set "UN=%~1"
- call :is_special_user "%UN%"
- if errorlevel 1 goto :eof
- set "USR_HIVE=%TARGET%:\Users\%UN%\NTUSER.DAT"
- if not exist "%USR_HIVE%" goto :eof
- "%REG%" load HKU\USR_SPV "%USR_HIVE%" >nul 2>nul
- if not errorlevel 1 goto spv_user_ok
- goto :eof
- :spv_user_ok
- call :merge_spv "HKU\USR_SPV\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" "windowsdefender"
- call :unload_hive "HKU\USR_SPV"
- goto :eof
- :merge_spv
- setlocal EnableDelayedExpansion
- set "SPKEY=%~1"
- set "ADD=%~2"
- set "SPV="
- call :get_filter
- if not defined FLT (
- endlocal
- goto :eof
- )
- for /f "tokens=2,*" %%A in ('"%REG%" query "%SPKEY%" /v SettingsPageVisibility 2^>nul ^| "%FLT%" /i "SettingsPageVisibility" 2^>nul') do set "SPV=%%B"
- set "SPV=!SPV: =!"
- if not defined SPV (
- set "SPV=hide:!ADD!"
- goto spv_write
- )
- set "SPMODE=hide"
- set "SPBODY=!SPV!"
- if /i "!SPV:~0,9!"=="showonly:" (
- set "SPMODE=showonly"
- set "SPBODY=!SPV:~9!"
- ) else if /i "!SPV:~0,5!"=="hide:" (
- set "SPBODY=!SPV:~5!"
- )
- set "PROBE=;!SPBODY!;"
- call :spv_squeeze_probe
- if /i not "!PROBE:;%ADD%;=!"=="!PROBE!" goto spv_contains
- if /i "!SPMODE!"=="showonly" (
- endlocal
- goto :eof
- )
- set "SPBODY=!PROBE:~1,-1!"
- if defined SPBODY (
- set "SPV=hide:!SPBODY!;!ADD!"
- ) else (
- set "SPV=hide:!ADD!"
- )
- goto spv_write
- :spv_contains
- if /i not "!SPMODE!"=="showonly" goto spv_info
- set "PROBE=!PROBE:;%ADD%;=;!"
- call :spv_squeeze_probe
- if not "!PROBE!"==";" goto spv_strip_ok
- set "SPV=hide:!ADD!"
- goto spv_write
- :spv_strip_ok
- set "SPV=showonly:!PROBE:~1,-1!"
- goto spv_write
- :spv_info
- endlocal
- goto :eof
- :spv_write
- "%REG%" add "%SPKEY%" /v SettingsPageVisibility /t REG_SZ /d "!SPV!" /f >nul 2>nul
- endlocal
- goto :eof
- :spv_squeeze_probe
- if "!PROBE:;;=;!"=="!PROBE!" goto :eof
- set "PROBE=!PROBE:;;=;!"
- goto spv_squeeze_probe
- :remove_onedrive_appx
- if not exist "%DISM%" goto :eof
- call :get_filter
- if not defined FLT goto :eof
- set "APPLIST=%TMPDIR%\dism_onedrive_%RANDOM%.txt"
- "%DISM%" /Image:%TARGET%:\ /Get-ProvisionedAppxPackages >"%APPLIST%" 2>nul
- if errorlevel 1 goto appx_dis_m_failed
- if not exist "%APPLIST%" goto appx_no_list
- for %%Z in ("%APPLIST%") do if %%~zZ==0 goto appx_no_list
- goto appx_have_list
- :appx_dis_m_failed
- if exist "%APPLIST%" del /f /q "%APPLIST%" >nul 2>nul
- goto :eof
- :appx_no_list
- if exist "%APPLIST%" del /f /q "%APPLIST%" >nul 2>nul
- goto :eof
- :appx_have_list
- set "LASTPKG="
- for /f "tokens=1,* delims=:" %%A in ('type "%APPLIST%" 2^>nul ^| "%FLT%" /i "OneDrive" 2^>nul') do call :do_remove_onedrive_appx "%%A" "%%B"
- del /f /q "%APPLIST%" >nul 2>nul
- goto :eof
- :do_remove_onedrive_appx
- set "APKG=%~2"
- if not defined APKG set "APKG=%~1"
- set "APKG=%APKG: =%"
- if not defined APKG goto :eof
- set "TAIL=%APKG:*_=%"
- if "%TAIL%"=="%APKG%" goto :eof
- if "%TAIL:_=%"=="%TAIL%" goto :eof
- if /i "%APKG%"=="%LASTPKG%" goto :eof
- set "LASTPKG=%APKG%"
- "%DISM%" /Image:%TARGET%:\ /Remove-ProvisionedAppxPackage /PackageName:%APKG% >nul 2>nul
- goto :eof
- :write_onedrive_policies
- set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
- "%REG%" load HKLM\OFF_SOFT3 "%SOFT_HIVE%" >nul 2>nul
- if not errorlevel 1 goto od_pol_ok
- goto :eof
- :od_pol_ok
- "%REG%" add "HKLM\OFF_SOFT3\Policies\Microsoft\Windows\OneDrive" /v DisableFileSyncNGSC /t REG_DWORD /d 1 /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT3\Microsoft\Windows\CurrentVersion\Run" /v OneDrive /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT3\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" /v OneDrive /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT3\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT3\Classes\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT3\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f >nul 2>nul
- "%REG%" delete "HKLM\OFF_SOFT3\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f >nul 2>nul
- call :unload_hive "HKLM\OFF_SOFT3"
- goto :eof
- :clean_user_onedrive_files
- set "UN=%~1"
- call :is_special_user "%UN%"
- if errorlevel 1 goto :eof
- call :safe_rmdir "%TARGET%:\Users\%UN%\AppData\Local\Microsoft\OneDrive"
- call :safe_rmdir "%TARGET%:\Users\%UN%\OneDrive"
- call :safe_delete "%TARGET%:\Users\%UN%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
- goto :eof
- :clean_default_user_onedrive
- set "DEF_HIVE=%TARGET%:\Users\Default\NTUSER.DAT"
- if not exist "%DEF_HIVE%" goto :eof
- "%REG%" load HKU\DEFTMP "%DEF_HIVE%" >nul 2>nul
- if errorlevel 1 goto :eof
- "%REG%" delete "HKU\DEFTMP\Software\Microsoft\Windows\CurrentVersion\Run" /v OneDrive /f >nul 2>nul
- "%REG%" delete "HKU\DEFTMP\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v OneDriveSetup /f >nul 2>nul
- call :unload_hive "HKU\DEFTMP"
- goto :eof
- :clean_one_user_onedrive
- set "UN=%~1"
- call :is_special_user "%UN%"
- if errorlevel 1 goto :eof
- set "USR_HIVE=%TARGET%:\Users\%UN%\NTUSER.DAT"
- if not exist "%USR_HIVE%" goto :eof
- "%REG%" load HKU\USRTMP "%USR_HIVE%" >nul 2>nul
- if errorlevel 1 goto :eof
- "%REG%" delete "HKU\USRTMP\Software\Microsoft\Windows\CurrentVersion\Run" /v OneDrive /f >nul 2>nul
- "%REG%" delete "HKU\USRTMP\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v OneDriveSetup /f >nul 2>nul
- call :unload_hive "HKU\USRTMP"
- goto :eof
- :unload_hive
- set "HIVE=%~1"
- "%REG%" unload "%HIVE%" >nul 2>nul
- if not errorlevel 1 goto :eof
- ping -n 3 127.0.0.1 >nul 2>nul
- "%REG%" unload "%HIVE%" >nul 2>nul
- goto :eof
- :bad_target
- echo [错误] 分区参数无效,应为单个盘符(如 D 或 D:)。
- goto :done
- :pe_self
- echo [错误] 不能以 PE 自身盘符为目标。
- goto :done
- :done
- echo [完成]按任意键退出 ...
- pause >nul
- endlocal
- exit /b 0
复制代码
|
评分
-
查看全部评分
|