Board logo

标题: [系统相关] [求助]批处理代码无法在开关机脚步运行 [打印本页]

作者: crist    时间: 2012-11-9 16:45     标题: [求助]批处理代码无法在开关机脚步运行

做了个清理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环境可以正常清理垃圾的这个代码,放在开关机脚本中运行却没有效果呢?
作者: Demon    时间: 2012-11-9 17:05

关机脚本的%userofile%不一样
作者: crist    时间: 2012-11-9 17:30

回复 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
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2