找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 1579|回复: 35

[分享] 离线删除[WD&OneDrive]

 荐 [复制链接]
发表于 2026-11-7 14:56:09 | 显示全部楼层 |阅读模式
用AI写的,自己试了没什么问题,不保证质量,不喜勿喷:

  1. @echo off
  2. chcp 936 >nul 2>nul
  3. setlocal EnableExtensions
  4. title 离线删除[Windows Defender ^& OneDrive]

  5. set "ESC="
  6. for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
  7. if defined ESC if "%ESC%"=="$E" set "ESC="
  8. if not defined ESC (
  9.     for /F "delims=" %%a in ('powershell -NoProfile -Command "[char]27"') do set "ESC=%%a"
  10. )

  11. set "TARGET="
  12. set "REG=%SystemRoot%\System32\reg.exe"
  13. set "TAKEOWN=%SystemRoot%\System32\takeown.exe"
  14. set "ICACLS=%SystemRoot%\System32\icacls.exe"
  15. set "FINDSTR=%SystemRoot%\System32\findstr.exe"
  16. set "FIND=%SystemRoot%\System32\find.exe"
  17. set "DISM=%SystemRoot%\System32\dism.exe"

  18. set "TMPDIR=%TEMP%"
  19. if not defined TMPDIR set "TMPDIR=%SystemRoot%\Temp"
  20. if not exist "%TMPDIR%" md "%TMPDIR%" >nul 2>nul
  21. if not exist "%TMPDIR%" set "TMPDIR=%SystemRoot%"
  22. if not "%TMPDIR:~3%"=="" if "%TMPDIR:~-1%"=="\" set "TMPDIR=%TMPDIR:~0,-1%"

  23. echo ================================================================
  24. echo  离线删除[Windows Defender ^& OneDrive]
  25. echo ================================================================

  26. if not "%~1"=="" goto :manual

  27. set "RETRY=0"
  28. :auto_scan
  29. set "TARGET="
  30. echo [自动] 正在扫描包含 Windows 安装的分区 ...
  31. 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 (
  32.     if not "%%D"=="%SystemDrive:~0,1%" (
  33.         if exist "%%D:\Windows\System32\config\SOFTWARE" (
  34.             if not defined TARGET (
  35.                 set "TARGET=%%D"
  36.                 echo   [找到] %%D:\
  37.             )
  38.         )
  39.     )
  40. )
  41. if defined TARGET goto :verify
  42. set /a RETRY+=1
  43. if %RETRY% lss 5 (
  44.     echo   [警告] 未找到目标分区,%RETRY%/5 次重试...
  45.     ping -n 3 127.0.0.1 >nul 2>nul
  46.     goto :auto_scan
  47. )
  48. echo   [错误] 多次扫描未找到目标分区。
  49. echo   请手动输入目标分区盘符(例如 C 或 C:),或按 Ctrl+C 退出。
  50. set "TARGET="
  51. set /p TARGET=目标分区:
  52. if not defined TARGET goto :done
  53. set "TARGET=%TARGET::=%"
  54. set "TARGET=%TARGET:\=%"
  55. if not defined TARGET goto :done
  56. if not "%TARGET:~1,1%"=="" goto :bad_target
  57. if /i "%TARGET%"=="%SystemDrive:~0,1%" goto :pe_self
  58. goto :verify

  59. :manual
  60. set "TARGET=%~1"
  61. set "TARGET=%TARGET::=%"
  62. set "TARGET=%TARGET:\=%"
  63. if not defined TARGET (
  64.     echo   [错误] 未指定目标分区。
  65.     goto :done
  66. )
  67. if not "%TARGET:~1,1%"=="" goto :bad_target
  68. if /i "%TARGET%"=="%SystemDrive:~0,1%" goto :pe_self

  69. :verify
  70. if not exist "%TARGET%:\Windows\System32\config\SOFTWARE" (
  71.     echo   [错误] %TARGET%:\ 不是有效的 Windows 分区。
  72.     goto :done
  73. )

  74. echo ================================================================
  75. echo  目标: %TARGET%:\
  76. echo ================================================================

  77. if not exist "%REG%" copy /y "%TARGET%:\Windows\System32\reg.exe" "%SystemRoot%\System32\" >nul 2>nul
  78. if not exist "%REG%" (
  79.     ping -n 3 127.0.0.1 >nul 2>nul
  80.     copy /y "%TARGET%:\Windows\System32\reg.exe" "%SystemRoot%\System32\" >nul 2>nul
  81. )
  82. if not exist "%REG%" (
  83.     echo   [错误] reg.exe 不可用,无法继续。
  84.     goto :done
  85. )
  86. if not exist "%TAKEOWN%" copy /y "%TARGET%:\Windows\System32\takeown.exe" "%SystemRoot%\System32\" >nul 2>nul
  87. if not exist "%ICACLS%" copy /y "%TARGET%:\Windows\System32\icacls.exe" "%SystemRoot%\System32\" >nul 2>nul
  88. if not exist "%FINDSTR%" copy /y "%TARGET%:\Windows\System32\findstr.exe" "%SystemRoot%\System32\" >nul 2>nul
  89. if not exist "%FIND%" copy /y "%TARGET%:\Windows\System32\find.exe" "%SystemRoot%\System32\" >nul 2>nul
  90. if not exist "%DISM%" copy /y "%TARGET%:\Windows\System32\dism.exe" "%SystemRoot%\System32\" >nul 2>nul
  91. echo.

  92. echo ================================================================
  93. echo  [1/2] 删除 Windows Defender
  94. echo ================================================================
  95. set /a PROG_CUR=0
  96. set /a PROG_MAX=12
  97. set "PROG_FIRST=1"
  98. call :draw_progress

  99. call :safe_rmdir "%TARGET%:\Program Files\Windows Defender"
  100. set /a PROG_CUR+=1
  101. call :draw_progress

  102. call :safe_rmdir "%TARGET%:\Program Files (x86)\Windows Defender"
  103. set /a PROG_CUR+=1
  104. call :draw_progress

  105. call :safe_rmdir "%TARGET%:\Program Files\Windows Defender Advanced Threat Protection"
  106. set /a PROG_CUR+=1
  107. call :draw_progress

  108. call :safe_rmdir "%TARGET%:\ProgramData\Microsoft\Windows Defender"
  109. set /a PROG_CUR+=1
  110. call :draw_progress

  111. call :safe_rmdir "%TARGET%:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection"
  112. set /a PROG_CUR+=1
  113. call :draw_progress

  114. call :safe_rmdir "%TARGET%:\ProgramData\Microsoft\Windows Security Health"
  115. set /a PROG_CUR+=1
  116. call :draw_progress

  117. call :safe_rmdir "%TARGET%:\Windows\System32\Tasks\Microsoft\Windows\Windows Defender"
  118. set /a PROG_CUR+=1
  119. call :draw_progress

  120. call :clean_taskcache "Windows Defender"
  121. set /a PROG_CUR+=1
  122. call :draw_progress

  123. call :disable_defender_services
  124. set /a PROG_CUR+=1
  125. call :draw_progress

  126. call :write_defender_policies
  127. set /a PROG_CUR+=1
  128. call :draw_progress

  129. call :remove_sechealth_advanced
  130. set /a PROG_CUR+=1
  131. call :draw_progress

  132. call :hide_spv_all_users
  133. set /a PROG_CUR+=1
  134. call :draw_progress

  135. echo ================================================================
  136. echo  [1/2] Windows Defender 清理完成
  137. echo ================================================================
  138. echo.

  139. echo ================================================================
  140. echo  [2/2] 删除 OneDrive
  141. echo ================================================================
  142. set /a PROG_CUR=0
  143. set /a PROG_MAX=11
  144. set "PROG_FIRST=1"
  145. call :draw_progress

  146. call :remove_onedrive_appx
  147. set /a PROG_CUR+=1
  148. call :draw_progress

  149. call :safe_delete "%TARGET%:\Windows\System32\OneDriveSetup.exe"
  150. set /a PROG_CUR+=1
  151. call :draw_progress

  152. call :safe_delete "%TARGET%:\Windows\SysWOW64\OneDriveSetup.exe"
  153. set /a PROG_CUR+=1
  154. call :draw_progress

  155. call :safe_rmdir "%TARGET%:\ProgramData\Microsoft OneDrive"
  156. set /a PROG_CUR+=1
  157. call :draw_progress

  158. call :safe_rmdir "%TARGET%:\Windows\System32\Tasks\Microsoft\OneDrive"
  159. set /a PROG_CUR+=1
  160. call :draw_progress

  161. call :safe_rmdir "%TARGET%:\Windows\System32\Tasks\Microsoft\Windows\OneDrive"
  162. set /a PROG_CUR+=1
  163. call :draw_progress

  164. call :clean_taskcache "OneDrive"
  165. set /a PROG_CUR+=1
  166. call :draw_progress

  167. call :safe_rmdir "%TARGET%:\OneDrive"
  168. set /a PROG_CUR+=1
  169. call :draw_progress

  170. for /d %%U in ("%TARGET%:\Users\*") do call :clean_user_onedrive_files "%%~nxU"
  171. set /a PROG_CUR+=1
  172. call :draw_progress

  173. call :write_onedrive_policies
  174. set /a PROG_CUR+=1
  175. call :draw_progress

  176. call :clean_default_user_onedrive
  177. for /d %%U in ("%TARGET%:\Users\*") do call :clean_one_user_onedrive "%%~nxU"
  178. set /a PROG_CUR+=1
  179. call :draw_progress

  180. echo ================================================================
  181. echo  [2/2] OneDrive 清理完成
  182. echo ================================================================
  183. echo.
  184. goto :done

  185. :draw_progress
  186. setlocal EnableDelayedExpansion
  187. set /a PCT=%PROG_CUR%*100/%PROG_MAX%
  188. set /a FILL=%PCT%*30/100
  189. set "BAR="
  190. for /l %%i in (1,1,30) do (
  191.     if %%i leq %FILL% (set "BAR=!BAR!#") else (set "BAR=!BAR!-")
  192. )
  193. if not defined ESC (
  194.     echo   进度: [!BAR!] !PCT!%%
  195.     endlocal
  196.     goto :eof
  197. )
  198. if "!PROG_FIRST!"=="1" (
  199.     <nul set /p "=  进度: [!BAR!] !PCT!%%"
  200.     echo.
  201.     endlocal
  202.     set "PROG_FIRST=0"
  203.     goto :eof
  204. )
  205. <nul set /p "=%ESC%[1A%ESC%[2K  进度: [!BAR!] !PCT!%%"
  206. echo.
  207. endlocal
  208. goto :eof

  209. :get_filter
  210. set "FLT=%FINDSTR%"
  211. if exist "%FLT%" goto :eof
  212. set "FLT=%FIND%"
  213. if exist "%FLT%" goto :eof
  214. set "FLT="
  215. goto :eof

  216. :is_special_user
  217. if /i "%~1"=="Default" exit /b 1
  218. if /i "%~1"=="Public" exit /b 1
  219. if /i "%~1"=="All Users" exit /b 1
  220. if /i "%~1"=="Default User" exit /b 1
  221. exit /b 0

  222. :safe_rmdir
  223. set "DIR=%~1"
  224. if not defined DIR goto :eof
  225. if not exist "%DIR%" goto :eof
  226. if exist "%TAKEOWN%" "%TAKEOWN%" /f "%DIR%" /r /d y >nul 2>nul
  227. if exist "%ICACLS%" "%ICACLS%" "%DIR%" /grant *S-1-5-32-544:F /t /c >nul 2>nul
  228. rd /s /q "%DIR%" >nul 2>nul
  229. goto :eof

  230. :safe_delete
  231. set "FILE=%~1"
  232. if not defined FILE goto :eof
  233. if not exist "%FILE%" goto :eof
  234. if exist "%TAKEOWN%" "%TAKEOWN%" /f "%FILE%" /a >nul 2>nul
  235. if exist "%ICACLS%" "%ICACLS%" "%FILE%" /grant *S-1-5-32-544:F >nul 2>nul
  236. del /f /q "%FILE%" >nul 2>nul
  237. goto :eof

  238. :disable_defender_services
  239. set "SYS_HIVE=%TARGET%:\Windows\System32\config\SYSTEM"
  240. "%REG%" load HKLM\OFF_SYS "%SYS_HIVE%" >nul 2>nul
  241. if not errorlevel 1 goto sys_loaded
  242. goto :eof

  243. :sys_loaded
  244. set "CSLIST=ControlSet001 ControlSet002 ControlSet003"
  245. set "CURN="
  246. call :get_filter
  247. if defined FLT (
  248.     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"
  249. )
  250. if defined CURN call :add_current_cs "%CURN%"
  251. for %%C in (%CSLIST%) do (
  252.     "%REG%" query "HKLM\OFF_SYS\%%C" >nul 2>nul
  253.     if not errorlevel 1 (
  254.         for %%S in (WinDefend WdNisSvc Sense WdBoot WdFilter WdNisDrv MDCoreSvc SecurityHealthService wscsvc SgrmBroker webthreatdefsvc webthreatdefusersvc) do call :set_service_disabled "%%S" "%%C"
  255.     )
  256. )
  257. call :unload_hive "HKLM\OFF_SYS"
  258. goto :eof

  259. :add_current_cs
  260. set "CUR=%~1"
  261. set /a NUM=%CUR% >nul 2>nul
  262. if not defined NUM goto :eof
  263. if %NUM% lss 1 goto :eof
  264. if %NUM% gtr 999 goto :eof
  265. set "PAD=00%NUM%"
  266. set "PAD=%PAD:~-3%"
  267. set "CSC=ControlSet%PAD%"
  268. set "HIT="
  269. for %%Q in (%CSLIST%) do if /i "%%Q"=="%CSC%" set "HIT=1"
  270. if defined HIT goto :eof
  271. set "CSLIST=%CSLIST% %CSC%"
  272. goto :eof

  273. :set_service_disabled
  274. set "SVC=%~1"
  275. set "CS=%~2"
  276. "%REG%" query "HKLM\OFF_SYS\%CS%\Services\%SVC%" >nul 2>nul
  277. if not errorlevel 1 goto svc_found
  278. goto :eof

  279. :svc_found
  280. "%REG%" add "HKLM\OFF_SYS\%CS%\Services\%SVC%" /v Start /t REG_DWORD /d 4 /f >nul 2>nul
  281. goto :eof

  282. :clean_taskcache
  283. set "TCKEYWORD=%~1"
  284. if not defined TCKEYWORD goto :eof
  285. call :get_filter
  286. if defined FLT goto tc_filter_ok
  287. goto :eof

  288. :tc_filter_ok
  289. set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
  290. "%REG%" load HKLM\OFF_TC "%SOFT_HIVE%" >nul 2>nul
  291. if not errorlevel 1 goto tc_loaded
  292. goto :eof

  293. :tc_loaded
  294. set "TCROOT=HKLM\OFF_TC\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache"
  295. "%REG%" delete "%TCROOT%\Tree\Microsoft\Windows\%TCKEYWORD%" /f >nul 2>nul
  296. "%REG%" delete "%TCROOT%\Tree\Microsoft\%TCKEYWORD%" /f >nul 2>nul
  297. set "TCLIST="
  298. for /f "tokens=*" %%K in ('"%REG%" query "%TCROOT%\Tasks" 2^>nul ^| "%FLT%" /i "{" 2^>nul') do call :tc_collect "%TCROOT%\Tasks\%%K"
  299. if defined TCLIST for %%K in (%TCLIST%) do call :taskcache_prune "%%K"
  300. call :unload_hive "HKLM\OFF_TC"
  301. goto :eof

  302. :tc_collect
  303. set "TKEY=%~1"
  304. if /i not "%TKEY:~0,5%"=="HKLM\" if /i not "%TKEY:~0,5%"=="HKEY_" goto :eof
  305. set "TCLIST=%TCLIST% %TKEY%"
  306. goto :eof

  307. :taskcache_prune
  308. set "TKEY=%~1"
  309. set "TPATH="
  310. for /f "tokens=2,*" %%A in ('"%REG%" query "%TKEY%" /v Path 2^>nul ^| "%FLT%" /i "Path" 2^>nul') do set "TPATH=%%B"
  311. if not defined TPATH goto :eof
  312. if /i "%FLT%"=="%FINDSTR%" (set "TCPAT=/i /c:") else (set "TCPAT=/i ")
  313. setlocal EnableDelayedExpansion
  314. echo(!TPATH!|"%FLT%" %TCPAT%"%TCKEYWORD%" >nul 2>nul
  315. if errorlevel 1 (
  316.     endlocal
  317.     goto :eof
  318. )
  319. endlocal
  320. "%REG%" delete "%TKEY%" /f >nul 2>nul
  321. goto :eof

  322. :write_defender_policies
  323. set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
  324. "%REG%" load HKLM\OFF_SOFT "%SOFT_HIVE%" >nul 2>nul
  325. if not errorlevel 1 goto def_pol_ok
  326. goto :eof

  327. :def_pol_ok
  328. "%REG%" add "HKLM\OFF_SOFT\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f >nul 2>nul
  329. "%REG%" add "HKLM\OFF_SOFT\Policies\Microsoft\Windows Defender" /v DisableAntiVirus /t REG_DWORD /d 1 /f >nul 2>nul
  330. "%REG%" add "HKLM\OFF_SOFT\Policies\Microsoft\Windows Defender" /v ServiceKeepAlive /t REG_DWORD /d 0 /f >nul 2>nul
  331. "%REG%" add "HKLM\OFF_SOFT\Policies\Microsoft\Windows Defender\Real-Time Protection" /v DisableRealtimeMonitoring /t REG_DWORD /d 1 /f >nul 2>nul
  332. "%REG%" delete "HKLM\OFF_SOFT\Microsoft\Windows\CurrentVersion\Run" /v SecurityHealth /f >nul 2>nul
  333. call :unload_hive "HKLM\OFF_SOFT"
  334. goto :eof

  335. :remove_sechealth_advanced
  336. set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
  337. "%REG%" load HKLM\OFF_SOFT2 "%SOFT_HIVE%" >nul 2>nul
  338. if not errorlevel 1 goto sec_ok
  339. goto :eof

  340. :sec_ok
  341. set "APPXROOT=HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore"
  342. set "DEPROV=%APPXROOT%\Deprovisioned"
  343. set "ENDOFLIFE=%APPXROOT%\EndOfLife"
  344. set "DEADEND=%APPXROOT%\Deleted\EndOfLife"

  345. call :purge_sec_entries "%APPXROOT%\Staged"
  346. call :purge_sec_entries "%APPXROOT%\InboxApplications"
  347. call :purge_sec_entries "%APPXROOT%\Applications"
  348. call :purge_sec_user_stores

  349. "%REG%" delete "HKLM\OFF_SOFT2\Classes\AppUserModelId\Windows.Defender" /f >nul 2>nul
  350. "%REG%" delete "HKLM\OFF_SOFT2\Classes\AppUserModelId\Microsoft.Windows.Defender" /f >nul 2>nul
  351. "%REG%" delete "HKLM\OFF_SOFT2\Classes\WindowsDefender" /f >nul 2>nul
  352. "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Explorer\ShellServiceObjects\{900c0763-5cad-4a34-bc1f-40cd513679d5}" /f >nul 2>nul
  353. "%REG%" delete "HKLM\OFF_SOFT2\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\ShellServiceObjects\{900c0763-5cad-4a34-bc1f-40cd513679d5}" /f >nul 2>nul
  354. "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Run" /v "SecurityHealth" /f >nul 2>nul
  355. "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Run" /v "WindowsDefender" /f >nul 2>nul
  356. "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" /v "SecurityHealth" /f >nul 2>nul
  357. "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" /v "Windows Defender" /f >nul 2>nul
  358. for %%i in (
  359.     2781761E-28E0-4109-99FE-B9D127C57AFE
  360.     2781761E-28E2-4109-99FE-B9D127C57AFE
  361.     195B4D07-3DE2-4744-BBF2-D90121AE785B
  362.     361290c0-cb1b-49ae-9f3e-ba1cbe5dab35
  363.     45F2C32F-ED16-4C94-8493-D72EF93A051B
  364.     6CED0DAA-4CDE-49C9-BA3A-AE163DC3D7AF
  365.     8a696d12-576b-422e-9712-01b9dd84b446
  366.     8C9C0DB7-2CBA-40F1-AFE0-C55740DD91A0
  367.     A2D75874-6750-4931-94C1-C99D3BC9D0C7
  368.     A7C452EF-8E9F-42EB-9F2B-245613CA0DC9
  369.     DACA056E-216A-4FD1-84A6-C306A017ECEC
  370.     E3C9166D-1D39-4D4E-A45D-BC7BE9B00578
  371.     F6976CF5-68A8-436C-975A-40BE53616D59
  372.     E48B2549-D510-4A76-8A5F-FC126A6215F0
  373. ) do (
  374.     "%REG%" delete "HKLM\OFF_SOFT2\Classes\CLSID\{%%i}" /f >nul 2>nul
  375.     "%REG%" delete "HKLM\OFF_SOFT2\Classes\WOW6432Node\CLSID\{%%i}" /f >nul 2>nul
  376. )

  377. "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows Security Health" /f >nul 2>nul
  378. "%REG%" delete "HKLM\OFF_SOFT2\Classes\CLSID\{BB64F8A7-BEE7-4E1A-AB8D-7D8273F7FDB6}" /f >nul 2>nul
  379. "%REG%" delete "HKLM\OFF_SOFT2\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{BB64F8A7-BEE7-4E1A-AB8D-7D8273F7FDB6}" /f >nul 2>nul

  380. call :unload_hive "HKLM\OFF_SOFT2"

  381. if exist "%DISM%" (
  382.     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
  383. )

  384. for %%F in (
  385.     "%TARGET%:\Windows\System32\SecurityHealthSystray.exe"
  386.     "%TARGET%:\Windows\System32\SecurityHealthService.exe"
  387.     "%TARGET%:\Windows\System32\SecurityHealthHost.exe"
  388.     "%TARGET%:\Windows\System32\SecurityHealthProxyStub.dll"
  389.     "%TARGET%:\Windows\System32\SecurityHealthCore.dll"
  390.     "%TARGET%:\Windows\System32\SecurityHealthSsoUdk.dll"
  391.     "%TARGET%:\Windows\System32\SecurityHealthSSO.dll"
  392.     "%TARGET%:\Windows\System32\SecurityHealthUdk.dll"
  393.     "%TARGET%:\Windows\System32\SecurityHealthAgent.dll"
  394.     "%TARGET%:\Windows\System32\SecurityAndMaintenance.png"
  395.     "%TARGET%:\Windows\System32\SecurityAndMaintenance_Error.png"
  396.     "%TARGET%:\Windows\SysWOW64\SecurityHealthSystray.exe"
  397.     "%TARGET%:\Windows\SysWOW64\SecurityHealthService.exe"
  398. ) do call :safe_delete "%%~F"

  399. for /d %%D in ("%TARGET%:\Windows\SystemApps\Microsoft.Windows.SecHealthUI*") do call :safe_rmdir "%%~fD"
  400. for /d %%D in ("%TARGET%:\Windows\SystemApps\Microsoft.SecHealthUI*") do call :safe_rmdir "%%~fD"
  401. for /d %%D in ("%TARGET%:\Program Files\WindowsApps\Microsoft.SecHealthUI*") do call :safe_rmdir "%%~fD"
  402. for /d %%D in ("%TARGET%:\Windows\System32\SecurityHealth*") do call :safe_rmdir "%%~fD"

  403. goto :eof

  404. :purge_sec_user_stores
  405. call :get_filter
  406. if not defined FLT goto :eof
  407. 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"
  408. goto :eof

  409. :purge_sec_entries
  410. set "ROOT=%~1"
  411. set "SECUSER=%~2"
  412. call :get_filter
  413. if defined FLT goto pur_have_filter
  414. goto :eof

  415. :pur_have_filter
  416. set "SECLIST="
  417. for /f "tokens=*" %%K in ('"%REG%" query "%ROOT%" 2^>nul ^| "%FLT%" /i "SecHealthUI" 2^>nul') do call :purge_sec_collect "%ROOT%\%%K"
  418. if defined SECLIST for %%K in (%SECLIST%) do call :purge_sec_one "%%K" "%SECUSER%"
  419. goto :eof

  420. :purge_sec_collect
  421. set "SKEY=%~1"
  422. if /i not "%SKEY:~0,5%"=="HKLM\" if /i not "%SKEY:~0,5%"=="HKEY_" goto :eof
  423. set "SECLIST=%SECLIST% %SKEY%"
  424. goto :eof

  425. :purge_sec_one
  426. set "SKEY=%~1"
  427. set "SPKG=%~nx1"
  428. set "SUSR=%~2"
  429. "%REG%" add "%DEPROV%\%SPKG%" /f >nul 2>nul
  430. if defined SUSR (
  431.     "%REG%" add "%ENDOFLIFE%\%SUSR%\%SPKG%" /f >nul 2>nul
  432.     "%REG%" add "%DEADEND%\%SUSR%\%SPKG%" /f >nul 2>nul
  433. ) else (
  434.     "%REG%" add "%ENDOFLIFE%\%SPKG%" /f >nul 2>nul
  435. )
  436. "%REG%" delete "%SKEY%" /f >nul 2>nul
  437. goto :eof

  438. :hide_spv_all_users
  439. set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
  440. "%REG%" load HKLM\OFF_SPV "%SOFT_HIVE%" >nul 2>nul
  441. if not errorlevel 1 goto spv_machine_ok
  442. goto spv_default

  443. :spv_machine_ok
  444. call :merge_spv "HKLM\OFF_SPV\Microsoft\Windows\CurrentVersion\Policies\Explorer" "windowsdefender"
  445. call :unload_hive "HKLM\OFF_SPV"

  446. :spv_default
  447. if not exist "%TARGET%:\Users\Default\NTUSER.DAT" goto spv_users
  448. "%REG%" load HKU\DEF_SPV "%TARGET%:\Users\Default\NTUSER.DAT" >nul 2>nul
  449. if not errorlevel 1 goto spv_def_ok
  450. goto spv_users

  451. :spv_def_ok
  452. call :merge_spv "HKU\DEF_SPV\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" "windowsdefender"
  453. call :unload_hive "HKU\DEF_SPV"

  454. :spv_users
  455. for /d %%U in ("%TARGET%:\Users\*") do call :hide_spv_one_user "%%~nxU"
  456. goto :eof

  457. :hide_spv_one_user
  458. set "UN=%~1"
  459. call :is_special_user "%UN%"
  460. if errorlevel 1 goto :eof
  461. set "USR_HIVE=%TARGET%:\Users\%UN%\NTUSER.DAT"
  462. if not exist "%USR_HIVE%" goto :eof
  463. "%REG%" load HKU\USR_SPV "%USR_HIVE%" >nul 2>nul
  464. if not errorlevel 1 goto spv_user_ok
  465. goto :eof

  466. :spv_user_ok
  467. call :merge_spv "HKU\USR_SPV\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" "windowsdefender"
  468. call :unload_hive "HKU\USR_SPV"
  469. goto :eof

  470. :merge_spv
  471. setlocal EnableDelayedExpansion
  472. set "SPKEY=%~1"
  473. set "ADD=%~2"
  474. set "SPV="
  475. call :get_filter
  476. if not defined FLT (
  477.     endlocal
  478.     goto :eof
  479. )
  480. for /f "tokens=2,*" %%A in ('"%REG%" query "%SPKEY%" /v SettingsPageVisibility 2^>nul ^| "%FLT%" /i "SettingsPageVisibility" 2^>nul') do set "SPV=%%B"
  481. set "SPV=!SPV: =!"
  482. if not defined SPV (
  483.     set "SPV=hide:!ADD!"
  484.     goto spv_write
  485. )
  486. set "SPMODE=hide"
  487. set "SPBODY=!SPV!"
  488. if /i "!SPV:~0,9!"=="showonly:" (
  489.     set "SPMODE=showonly"
  490.     set "SPBODY=!SPV:~9!"
  491. ) else if /i "!SPV:~0,5!"=="hide:" (
  492.     set "SPBODY=!SPV:~5!"
  493. )
  494. set "PROBE=;!SPBODY!;"
  495. call :spv_squeeze_probe
  496. if /i not "!PROBE:;%ADD%;=!"=="!PROBE!" goto spv_contains
  497. if /i "!SPMODE!"=="showonly" (
  498.     endlocal
  499.     goto :eof
  500. )
  501. set "SPBODY=!PROBE:~1,-1!"
  502. if defined SPBODY (
  503.     set "SPV=hide:!SPBODY!;!ADD!"
  504. ) else (
  505.     set "SPV=hide:!ADD!"
  506. )
  507. goto spv_write

  508. :spv_contains
  509. if /i not "!SPMODE!"=="showonly" goto spv_info
  510. set "PROBE=!PROBE:;%ADD%;=;!"
  511. call :spv_squeeze_probe
  512. if not "!PROBE!"==";" goto spv_strip_ok
  513. set "SPV=hide:!ADD!"
  514. goto spv_write

  515. :spv_strip_ok
  516. set "SPV=showonly:!PROBE:~1,-1!"
  517. goto spv_write

  518. :spv_info
  519. endlocal
  520. goto :eof

  521. :spv_write
  522. "%REG%" add "%SPKEY%" /v SettingsPageVisibility /t REG_SZ /d "!SPV!" /f >nul 2>nul
  523. endlocal
  524. goto :eof

  525. :spv_squeeze_probe
  526. if "!PROBE:;;=;!"=="!PROBE!" goto :eof
  527. set "PROBE=!PROBE:;;=;!"
  528. goto spv_squeeze_probe

  529. :remove_onedrive_appx
  530. if not exist "%DISM%" goto :eof
  531. call :get_filter
  532. if not defined FLT goto :eof
  533. set "APPLIST=%TMPDIR%\dism_onedrive_%RANDOM%.txt"
  534. "%DISM%" /Image:%TARGET%:\ /Get-ProvisionedAppxPackages >"%APPLIST%" 2>nul
  535. if errorlevel 1 goto appx_dis_m_failed
  536. if not exist "%APPLIST%" goto appx_no_list
  537. for %%Z in ("%APPLIST%") do if %%~zZ==0 goto appx_no_list
  538. goto appx_have_list

  539. :appx_dis_m_failed
  540. if exist "%APPLIST%" del /f /q "%APPLIST%" >nul 2>nul
  541. goto :eof

  542. :appx_no_list
  543. if exist "%APPLIST%" del /f /q "%APPLIST%" >nul 2>nul
  544. goto :eof

  545. :appx_have_list
  546. set "LASTPKG="
  547. for /f "tokens=1,* delims=:" %%A in ('type "%APPLIST%" 2^>nul ^| "%FLT%" /i "OneDrive" 2^>nul') do call :do_remove_onedrive_appx "%%A" "%%B"
  548. del /f /q "%APPLIST%" >nul 2>nul
  549. goto :eof

  550. :do_remove_onedrive_appx
  551. set "APKG=%~2"
  552. if not defined APKG set "APKG=%~1"
  553. set "APKG=%APKG: =%"
  554. if not defined APKG goto :eof
  555. set "TAIL=%APKG:*_=%"
  556. if "%TAIL%"=="%APKG%" goto :eof
  557. if "%TAIL:_=%"=="%TAIL%" goto :eof
  558. if /i "%APKG%"=="%LASTPKG%" goto :eof
  559. set "LASTPKG=%APKG%"
  560. "%DISM%" /Image:%TARGET%:\ /Remove-ProvisionedAppxPackage /PackageName:%APKG% >nul 2>nul
  561. goto :eof

  562. :write_onedrive_policies
  563. set "SOFT_HIVE=%TARGET%:\Windows\System32\config\SOFTWARE"
  564. "%REG%" load HKLM\OFF_SOFT3 "%SOFT_HIVE%" >nul 2>nul
  565. if not errorlevel 1 goto od_pol_ok
  566. goto :eof

  567. :od_pol_ok
  568. "%REG%" add "HKLM\OFF_SOFT3\Policies\Microsoft\Windows\OneDrive" /v DisableFileSyncNGSC /t REG_DWORD /d 1 /f >nul 2>nul
  569. "%REG%" delete "HKLM\OFF_SOFT3\Microsoft\Windows\CurrentVersion\Run" /v OneDrive /f >nul 2>nul
  570. "%REG%" delete "HKLM\OFF_SOFT3\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" /v OneDrive /f >nul 2>nul
  571. "%REG%" delete "HKLM\OFF_SOFT3\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f >nul 2>nul
  572. "%REG%" delete "HKLM\OFF_SOFT3\Classes\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f >nul 2>nul
  573. "%REG%" delete "HKLM\OFF_SOFT3\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f >nul 2>nul
  574. "%REG%" delete "HKLM\OFF_SOFT3\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f >nul 2>nul
  575. call :unload_hive "HKLM\OFF_SOFT3"
  576. goto :eof

  577. :clean_user_onedrive_files
  578. set "UN=%~1"
  579. call :is_special_user "%UN%"
  580. if errorlevel 1 goto :eof
  581. call :safe_rmdir "%TARGET%:\Users\%UN%\AppData\Local\Microsoft\OneDrive"
  582. call :safe_rmdir "%TARGET%:\Users\%UN%\OneDrive"
  583. call :safe_delete "%TARGET%:\Users\%UN%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
  584. goto :eof

  585. :clean_default_user_onedrive
  586. set "DEF_HIVE=%TARGET%:\Users\Default\NTUSER.DAT"
  587. if not exist "%DEF_HIVE%" goto :eof
  588. "%REG%" load HKU\DEFTMP "%DEF_HIVE%" >nul 2>nul
  589. if errorlevel 1 goto :eof
  590. "%REG%" delete "HKU\DEFTMP\Software\Microsoft\Windows\CurrentVersion\Run" /v OneDrive /f >nul 2>nul
  591. "%REG%" delete "HKU\DEFTMP\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v OneDriveSetup /f >nul 2>nul
  592. call :unload_hive "HKU\DEFTMP"
  593. goto :eof

  594. :clean_one_user_onedrive
  595. set "UN=%~1"
  596. call :is_special_user "%UN%"
  597. if errorlevel 1 goto :eof
  598. set "USR_HIVE=%TARGET%:\Users\%UN%\NTUSER.DAT"
  599. if not exist "%USR_HIVE%" goto :eof
  600. "%REG%" load HKU\USRTMP "%USR_HIVE%" >nul 2>nul
  601. if errorlevel 1 goto :eof
  602. "%REG%" delete "HKU\USRTMP\Software\Microsoft\Windows\CurrentVersion\Run" /v OneDrive /f >nul 2>nul
  603. "%REG%" delete "HKU\USRTMP\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v OneDriveSetup /f >nul 2>nul
  604. call :unload_hive "HKU\USRTMP"
  605. goto :eof

  606. :unload_hive
  607. set "HIVE=%~1"
  608. "%REG%" unload "%HIVE%" >nul 2>nul
  609. if not errorlevel 1 goto :eof
  610. ping -n 3 127.0.0.1 >nul 2>nul
  611. "%REG%" unload "%HIVE%" >nul 2>nul
  612. goto :eof

  613. :bad_target
  614. echo   [错误] 分区参数无效,应为单个盘符(如 D 或 D:)。
  615. goto :done

  616. :pe_self
  617. echo   [错误] 不能以 PE 自身盘符为目标。
  618. goto :done

  619. :done
  620. echo [完成]按任意键退出 ...
  621. pause >nul
  622. endlocal
  623. exit /b 0
复制代码


评分

参与人数 1无忧币 +5 收起 理由
dayeye + 5

查看全部评分

发表于 2026-11-7 15:34:35 | 显示全部楼层
一款很实用的脚本啊,下载试用了
回复

使用道具 举报

发表于 2026-11-7 15:36:03 | 显示全部楼层
回复

使用道具 举报

发表于 2026-11-7 15:49:02 | 显示全部楼层
本帖最后由 忧心的启 于 2026-11-7 15:58 编辑

和之前那些比较过吗?这个比较干净还是什么?,给个建议,不用判断系统在哪,一般固定C盘就行,实在不行,有时在PE下盘符乱的,写一句输入盘符就行(看到最后有手动输入了)。
我之前在论坛下载过三套件删除。还有Edge呢?

点评

跟这里的: https://bbs.wuyou.net/forum.php?mod=viewthread&tid=445235 对比过,没有上面的干净,而且也不用SuperUser.EXE提权, 但适合我自己用,我是都是用自己写的东西安装系统的,在: DISM.EXE /Apply-Image  详情 回复 发表于 2026-11-7 16:18
回复

使用道具 举报

发表于 2026-11-7 15:56:33 | 显示全部楼层
离线删除干净

点评

对的,在线的也可以,重启一下也会很干净,论坛有大神做有,我下载有了离线的了有下载。  详情 回复 发表于 2026-11-7 16:00
回复

使用道具 举报

发表于 2026-11-7 16:00:09 | 显示全部楼层

对的,在线的也可以,重启一下也会很干净,论坛有大神做有,我下载有了离线的了有下载。
回复

使用道具 举报

 楼主| 发表于 2026-11-7 16:18:53 | 显示全部楼层
本帖最后由 0cat0 于 2026-11-7 16:20 编辑
忧心的启 发表于 2026-11-7 15:49
和之前那些比较过吗?这个比较干净还是什么?,给个建议,不用判断系统在哪,一般固定C盘就行,实在不行, ...

跟这里的:
https://bbs.wuyou.net/forum.php?mod=viewthread&tid=445235
对比过,没有上面的干净,而且也不用SuperUser.EXE提权,
但适合我自己用,我都是用自己写的东西安装系统的,在:
DISM.EXE /Apply-Image /ImageFile,
后运行脚本,复制Unattend文件,最后重启电脑,就直接进系统了

点评

我测试了一下,WD,很干净,OD还有一点。  详情 回复 发表于 2026-11-7 16:22
回复

使用道具 举报

发表于 2026-11-7 16:22:41 | 显示全部楼层
0cat0 发表于 2026-11-7 16:18
跟这里的:
https://bbs.wuyou.net/forum.php?mod=viewthread&tid=445235
对比过,没有上面的干净,而且也 ...

我测试了一下,WD,很干净,OD还有一点。

202611716936660.png 2026117161848137.png 202611716205646.png

点评

你用的这个脚本界面好像见过,是哪个贴子里的?  发表于 7 天前
多谢测试,OneDrive除下的我看你的截图,有一些找不到,一些是有的,可能系统版本不一样,我自己用的系统是24H2 LTSC,测试脚本用的是23H2,26H1,26H2,算了剩下的就留给各位补全了  详情 回复 发表于 2026-11-7 16:42
回复

使用道具 举报

发表于 2026-11-7 16:26:43 | 显示全部楼层
离线删除更多应用
回复

使用道具 举报

发表于 2026-11-7 16:33:12 | 显示全部楼层
试试怎么样
回复

使用道具 举报

发表于 2026-11-7 16:36:01 | 显示全部楼层
试试怎么样
回复

使用道具 举报

 楼主| 发表于 2026-11-7 16:42:23 | 显示全部楼层
忧心的启 发表于 2026-11-7 16:22
我测试了一下,WD,很干净,OD还有一点。

多谢测试,OneDrive除下的我看你的截图,有一些找不到,一些是有的,可能系统版本不一样,我自己用的系统是24H2 LTSC,测试脚本用的是23H2,26H1,26H2,算了剩下的就留给各位补全了
回复

使用道具 举报

发表于 2026-11-7 16:44:26 | 显示全部楼层
谢谢分享,能删除更多辣鸡就好了
回复

使用道具 举报

发表于 2026-11-7 17:04:13 | 显示全部楼层
据说AI在批处理方面已经很牛了
回复

使用道具 举报

发表于 2026-11-7 17:52:46 | 显示全部楼层
试试效果
回复

使用道具 举报

发表于 2026-11-7 18:24:19 | 显示全部楼层
楼主辛苦了!  非常感谢你的分享!
回复

使用道具 举报

发表于 2026-11-7 18:43:57 来自手机 | 显示全部楼层
多谢分享
回复

使用道具 举报

发表于 2026-11-7 18:44:23 来自手机 | 显示全部楼层
多谢分享!
回复

使用道具 举报

发表于 2026-11-7 19:19:36 | 显示全部楼层
谢谢分享
回复

使用道具 举报

发表于 2026-11-7 20:36:15 | 显示全部楼层
楼主辛苦了
回复

使用道具 举报

发表于 2026-11-7 21:02:49 | 显示全部楼层
回复

使用道具 举报

发表于 2026-11-7 21:06:34 来自手机 | 显示全部楼层
感谢分享
回复

使用道具 举报

发表于 2026-11-7 22:22:18 来自手机 | 显示全部楼层
用哪个AI写的
回复

使用道具 举报

发表于 2026-11-7 22:23:55 | 显示全部楼层
感谢楼主分享!试试这个看看吧
回复

使用道具 举报

发表于 2026-11-7 23:02:37 | 显示全部楼层
路过支持下
回复

使用道具 举报

发表于 2026-11-7 23:09:56 | 显示全部楼层
没见过这种,学习一下
回复

使用道具 举报

发表于 7 天前 | 显示全部楼层
好长好长的代码,学习了
回复

使用道具 举报

发表于 7 天前 | 显示全部楼层
收藏 谢谢
回复

使用道具 举报

发表于 7 天前 | 显示全部楼层
回复

使用道具 举报

发表于 6 天前 | 显示全部楼层
收藏 谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|捐助支持|无忧启动 ( 闽ICP备05002490号-1|闽公网安备35020302032614号 )

GMT+8, 2026-11-15 12:42

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表