[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] [求助]批处理代码无法在开关机脚步运行

做了个清理chrome垃圾的批处理,代码如下:
  1. @echo off
  2. title %~n0
  3. if exist "%userprofile%\Local Settings\Application Data\Google\Chrome" (
  4. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*Archived*" >nul 2>nul
  5. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*Cookies*" >nul 2>nul
  6. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*History*" >nul 2>nul
  7. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*Index*" >nul 2>nul
  8. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*journal*" >nul 2>nul
  9. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*Links*" >nul 2>nul
  10. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*Session*" >nul 2>nul
  11. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*Shortcuts*" >nul 2>nul
  12. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*Sites*" >nul 2>nul
  13. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*Tabs*" >nul 2>nul
  14. del/f/q/s/a "%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\*.bak" >nul 2>nul
  15. for /f "delims=" %%a in ('dir/ad/b/s "%userprofile%\local settings\application data\google\chrome\*cache*"') do (if exist "%%a" rd/q/s "%%a")>NUL 2>NUL
  16. for /f "delims=" %%b in ('dir/ad/b/s "%userprofile%\local settings\application data\google\chrome\*databases*"') do (if exist "%%b" rd/q/s "%%b")>NUL 2>NUL
  17. for /f "delims=" %%c in ('dir/ad/b/s "%userprofile%\local settings\application data\google\chrome\*Local Storage*"') do (if exist "%%c" rd/q/s "%%c")>NUL 2>NUL
  18. for /f "delims=" %%d in ('dir/ad/b/s "%userprofile%\local settings\application data\google\chrome\*Media Cache*"') do (if exist "%%d" rd/q/s "%%d")>NUL 2>NUL
  19. )
  20. pause
复制代码
我的问题是:为何在Windows环境可以正常清理垃圾的这个代码,放在开关机脚本中运行却没有效果呢?

关机脚本的%userofile%不一样

TOP

回复 2# Demon


    那么我将代码改成以下可以吗?
  1. @echo off
  2. title %~n0
  3. for /f "delims=" %%i in ('dir/ad/b/s/o "%systemdrive%\Chrome"') do (
  4. if not exist "%%i\Application" if exist "%%i\User Data" (
  5.   set chrometemp="%%i\User Data"
  6.   del/f/q/s/a "%chrometemp%\*Archived*" >nul 2>nul
  7.   del/f/q/s/a "%chrometemp%\*Cookies*" >nul 2>nul
  8.   del/f/q/s/a "%chrometemp%\*History*" >nul 2>nul
  9.   del/f/q/s/a "%chrometemp%\*Index*" >nul 2>nul
  10.   del/f/q/s/a "%chrometemp%\*journal*" >nul 2>nul
  11.   del/f/q/s/a "%chrometemp%\*Links*" >nul 2>nul
  12.   del/f/q/s/a "%chrometemp%\*Session*" >nul 2>nul
  13.   del/f/q/s/a "%chrometemp%\*Shortcuts*" >nul 2>nul
  14.   del/f/q/s/a "%chrometemp%\*Sites*" >nul 2>nul
  15.   del/f/q/s/a "%chrometemp%\*Tabs*" >nul 2>nul
  16.   del/f/q/s/a "%chrometemp%\*.bak" >nul 2>nul
  17.   for /f "delims=" %%a in ('dir/ad/b/s "%%i\*cache*"') do (if exist "%%a" rd/q/s "%%a")>NUL 2>NUL
  18.   for /f "delims=" %%b in ('dir/ad/b/s "%%i\*databases*"') do (if exist "%%b" rd/q/s "%%b")>NUL 2>NUL
  19.   for /f "delims=" %%c in ('dir/ad/b/s "%%i\*Local Storage*"') do (if exist "%%c" rd/q/s "%%c")>NUL 2>NUL
  20.   for /f "delims=" %%d in ('dir/ad/b/s "%%i\*Media Cache*"') do (if exist "%%d" rd/q/s "%%d")>NUL 2>NUL
  21. )
  22. )
  23. pause
复制代码

TOP

返回列表