Articles การเคลียร์ Temp Windows XP/2003/Vista/7/8/10/2008/2012/2016

การเคลียร์ Temp Windows XP/2003/Vista/7/8/10/2008/2012/2016

พอดีไปค้นเจอมาเลยเอามาลงไว้คิดว่าน่าจะใช้งานกันบ่อยแน่ๆ

หลาย ๆ ท่านต้องเสียเวลาลบ Temp ต่อละ Profile ยิ่งถ้าใช้ Remote Desktop แล้วอันนี้เหมาะเลย
User บอกเครี่องช้า ๆ ก็เซฟวางไว้ที่ All user Public ให้คลิ๊กเองเลย ไอทีเรา ๆ ก็ใช้ได้สบาย ๆ อยากลบอะไรเพิ่มก็
เพิ่มเขาไปเลยได้ครับ ด้านบนตรวจสอบเวอร์ชั่น Windows เฉยๆ ถ้า XP ทำก่อน Else นอกนั้นก็หลัง Else

===== คัดลอกด้านล่างนี้เซฟเป็นไฟล์ DeleteTempAll.bat ไว้หน้าจอได้เลย========================
รหัส:
@echo off

Rem Written by Twisty.  Created 1/19/2011.  Modified 6/28/2011.
Rem Edit by Mr. Pairoj Chanda  Created 17/05/2014 Modified 17/05/2015.
Rem This script for deletes temp files

    Rem Identify version of Windows
    SET WinVer=Unknown
    VER | FINDSTR /IL "5.1." > NUL
    IF %ERRORLEVEL% EQU 0 SET WinVer=XP
    rem 5.2 is actually Server 2003, but for our purposes it's the same as XP
    VER | FINDSTR /IL "5.2." > NUL
    IF %ERRORLEVEL% EQU 0 SET WinVer=XP
    VER | FINDSTR /IL "6.0." > NUL
    IF %ERRORLEVEL% EQU 0 SET WinVer=VISTA
    rem 6.1 is actually Windows 7, Server 2008R2, but for our purposes it's the same as Vista
    VER | FINDSTR /IL "6.1." > NUL
    IF %ERRORLEVEL% EQU 0 SET WinVer=VISTA

rem 6.3 is actually Windows 8,Server 2012R2 , but for our purposes it's the same as Vista
    VER | FINDSTR /IL "6.3." > NUL
    IF %ERRORLEVEL% EQU 0 SET WinVer=VISTA

rem 10. is actually Windows 10, but for our purposes it's the same as Vista
    VER | FINDSTR /IL "10.0." > NUL
    IF %ERRORLEVEL% EQU 0 SET WinVer=VISTA

    rem Ask user the version if we cannot automatically determine
    If Not "%WinVer%" EQU "Unknown" Goto :SetUserProfPath

    Set /P Response="Select OS  [X]XP/2003 [V]Vista/7/8/10/2008/2012/2016: "
    If /i "%Response%" EQU "X" Set WinVer=XP
    If /i "%Response%" EQU "V" Set WinVer=VISTA
    If "%WinVer%" EQU "" Echo Invalid response. Exiting.&goto :eof

:SetUserProfPath
    If %WinVer% EQU XP (
        Set UserProfileRootPath=C:\Documents and Settings
    ) Else (
        Set UserProfileRootPath=C:\Users
    )

    Call :RemoveSubfoldersAndFiles %SystemRoot%\Temp

    Rem Walk through each user profile folder
    Rem This convoluted command is necessary to ensure we process hidden and system folders too
    for /f "delims=" %%D in ('dir /ad /b "%UserProfileRootPath%"') DO Call :ProcessProfileFolder %UserProfileRootPath%\%%D

    Echo.
    Echo Finished! Press a key to exit...
    Pause>Nul

goto :EOF

:ProcessProfileFolder

    Set FolderName=%*

    Rem Leave if it's not a user profile folder
    If Not Exist "%FolderName%\ntuser.dat" goto :EOF

    Rem Leave it's a profile folder on the exclude list
    Rem If /I "%FolderName%" EQU "%UserProfileRootPath%\Default" goto :EOF
    Rem If /I "%FolderName%" EQU "%UserProfileRootPath%\Default User" goto :EOF
    Rem If /I "%FolderName%" EQU "%UserProfileRootPath%\NetworkService" goto :EOF
    Rem If /I "%FolderName%" EQU "%UserProfileRootPath%\LocalService" goto :EOF

    Set UserProfilePath=%FolderName%

    Rem Clean up these folders
    If %WinVer% EQU XP (
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Temp\*.auc
         Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Temp
         Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Temporary Internet Files
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Application Data\Mozilla\Firefox\Profiles
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Application Data\Google\Chrome\User Data
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Application Data\Microsoft\Internet Explorer
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Application Data\Sun\Java\Deployment\cache
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Cookies

     ) Else (
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\*.auc
         Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Temp
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\LocalLow\Temp
         Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\LocalLow\Sun\Java\Deployment\cache
         Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Microsoft\Windows\Temporary Internet Files
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Microsoft\Windows\INetCache
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Microsoft\Windows\INetCookies
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Mozilla\Firefox\Profiles
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Google\Chrome\User Data
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Microsoft\Windows\Internet Explorer

    )

goto :EOF

:RemoveSubfoldersAndFiles

    Set FolderRootPath=%*

    Rem Confirm target folder exists
    If Not Exist "%FolderRootPath%" Goto :EOF

    Rem Make the folder to clean current and confirm it exists...
    CD /D %FolderRootPath%

    Rem Confirm we switched directories
    If /I "%CD%" NEQ "%FolderRootPath%" Goto :EOF

    Rem ...so that this command cannot delete the folder, only everything in it
    Echo Purging %CD%
    RD /S /Q . >>nul 2>>&1

goto :EOF

(y)
 


กลับ
ยอดนิยม