我使用这个脚本来清除所有用户的历史记录、cookie 和缓存(临时 Internet 文件),并且它还应该清除临时目录,但是似乎有些问题。
我认为有两件事混淆了,%temp% 变量(在我的环境中为 D:\TEMP)和 %userprofile% 中的用户临时目录
:: Works on Win XP -and- on Win 7
@echo off
Set "RegKey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
set "regkey2=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\shell folders"
call:getspecialfolders "Cache, History, Cookies"
For /f "tokens=*" %%? in (
'Reg.exe QUERY "%RegKey%" ^|findstr /ric:"\S-1-5-21-[0-9]*-[0-9]*-[0-9]*-[0-9]*$"'
) do (
For /f "tokens=2,*" %%A in (
'Reg.exe QUERY "%%?" /v ProfileImagePath ^|find /i "ProfileImagePath"'
) do call:Go %%B
)
start ""/w "%windir%\system32\RunDll32.exe" InetCpl.cpl,ClearMyTracksByProcess 255
:end ***
goto:EOF
:Go
call Set "Target=%*"
If EXIST "%Target%" call:Clear "%Target%"
exit /b 0
:Clear
REM echo.&echo.%~1\%$$Cache%
pushD "%~1\%$$Cache%" &&(
rmdir /S /Q .
popD)2>C:\test1_TEMP_IE.txt
REM echo.&echo.%~1\%$$History%\History.IE5
REM pushD "%~1\%$$History%\History.IE5" &&(
REM rmdir /S /Q .
REM popD)2>C:\test1_History_IE.txt
REM echo.&echo.%~1\%$$History%
pushD "%~1\%$$History%" &&(
rmdir /S /Q .
popD)2>C:\test1_History.txt
REM echo.&echo.%~1\%$$Cookies%
pushD "%~1\%$$Cookies%" &&(
rmdir /S /Q .
popD)2>C:\test1_Cookies.txt
ECHO.&echo.%~1\%$$temp%
pushD "%~1\%$$temp%" &&(
rmdir /S /Q .
popD)2>C:\test1_Temp.txt
exit /b 0
:getspecialfolders
Set "FoldersToClear=%~1"
For %%* in (%FoldersToClear%) Do (
For /f "tokens=2,*" %%A in (
'reg.exe query "%regkey2%" /v %%* ^|find /i "%%~*"'
) do Call:sf1 "%%~B" "%%~*"
)
Call:sf2 "%temp%" "temp" "%userprofile%"
exit /b 0
:sf1
Call set "sf=%~1"
Call set "$$%~2=%%sf:%userprofile%\=%%"
exit /b 0
:sf2
Call set "sf=%~1"
call Set "usr=%~dpns3"
Call set "$$%~2=%%sf:%usr%\=%%"
exit /b 0
但不知何故,我无法让最后的“临时部分”运行,因此它会清理 %temp%(在我的环境中为 D:\Temp),还会在 %userprofile% 中找到所有“临时目录”。
IE。例如,这对 %temp% 有效:
PushD "%Temp%" && (
ATTRIB -S -H -R -A /D /S & (
For /f "Tokens=*" %%* in ('dir "%Temp%" /B') Do (
RD "%Temp%\%%*" /S /Q || Del /F /S /Q "%Temp%\%%*"))&PopD)2>c:\test0b_TEMP.txt
还有这个。适用于“用户临时”:
::Set Search directory to "Documents and Settings" folder
(Set Target=%AllUsersProfile:~0,-10%)
title,Finding the Temp subfolders in %Target%&COLOR 9E
If EXIST "%Target%",(
For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
cd/D "%target%\%%*\Local Settings\Temp" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
)
我希望有人能帮助我修复脚本,我认为它在:sf2 中和/或与 %temp% 部分结合,不知何故有两件事混淆了(“用户温度”和“环境温度”)。
答案1
这似乎是一个解决方法:
代替
ECHO.&echo.%~1\%$$temp%
pushD "%~1\%$$temp%" &&(
rmdir /S /Q .
popD)2>C:\test1_Temp.tx
使用
IF "%$$temp%"=="%$$temp:*:=%" (SET "tmppath=%~1\%$$temp%") ELSE SET "tmppath=%$$temp%"
ECHO.&echo.%tmppath%
pushD "%tmppath%" &&(
rmdir /S /Q .
popD)2>C:\test1_Temp.txt
致谢:安德烈