script to empty %temp% and Prefetch folders


  1. Posts : 38
    windows 8.1
       #1

    script to empty %temp% and Prefetch folders


    I need to make a script to empty both folders (temp & Prefetch) folders please.
      My Computer


  2. Posts : 1,247
    Windows 10
       #2

    You should try to make it yourself you are asking for something that can be done in one line and the other ones you have been asking for are minimal effort also that don't require much logic.
      My Computer


  3. Posts : 5,347
    Windows 11 Pro 64-bit
       #3

    Here you go, this script deletes temporary files.

    Code:
    :: Batch Script Created by FreeBooter
    
    @Echo Off & Cls
    
    net sess>nul 2>&1||(powershell start cmd -ArgumentList """/c %~0""" -verb Runas & exit)
    
    Call :IsAdmin
    
    Mode CON LINES=5 COLS=50 & Color 0E
    
    Echo                   PLEASE WAIT... 
    
    :: This command deletes the oldest shadow copy on drive C
    vssadmin delete shadows /for=c: /oldest 2>&1 >nul
    
    ::Creating System Restore point 
    Wmic.exe /Namespace:\\root\default Path SystemRestore Call CreateRestorePoint "Before Deleting Temp Files", 100, 12 
    
    
    ::    CLEANUP STAGE
    Reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files"  /v LastAccess /t REG_DWORD /d "0" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\BranchCache" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Service Pack Cleanup" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error memory dump files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error minidump files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Upgrade Discarded Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\User file versions" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Defender" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Archive Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Queue Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Archive Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Queue Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows ESD installation files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    Reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Upgrade Log Files" /v "StateFlags0064" /t REG_DWORD /d "2" /f 2>&1 >nul
    
    
    
    Cls & Mode CON  LINES=10 COLS=50 & Color 1E & Title Created by FREEBOOTER
    Echo.
    Echo.
    Echo. 
    Echo.
    Echo.
    Echo.
    Echo.
    Echo.
    Echo.
    Echo.
    Echo.
    Echo. 
    Echo.
    Echo.
    Echo.
    Echo           浜様様様様様様様様様様様様融 
    Echo            DELETING TEMPORARY FILES   
    Echo           藩様様様様様様様様様様様様夕
    Echo.
    
    CLEANMGR /sagerun:64 
    
    
    
    Cls
    :: Clear Temporary Folder.
    Cd %TMP% 
    For /f "tokens=*" %%a in ('Dir /b %LOCALAPPDATA%\Temp') do (
    Echo Y | Rd /s /q "%%a" 2>NUL 1>NUL 
    If Exist "%%a" Echo Y | Del /a /f "%%a" 2>NUL 1>NUL 
    )
    Echo. 
    Echo.
    Echo.
    Echo.
    Echo. 
    Echo.
    Echo.
    Echo.
    Echo. 
    Echo.
    Echo.
    Echo.
    Echo. 
    Echo        FINNISH DELETING TEMPORARY FILES 
    Echo.
    Echo.
    ping -n 5 localhost >Nul
    
    
    Cls
    
    Del /a /f /q "%SystemRoot%\Prefetch\*"
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Cls & Mode CON  LINES=12 COLS=80 & Color 1E & Title Created by FREEBOOTER
    
    Cd  %SystemRoot%\System32
    
    Net Start TrustedInstaller 2>NUL 1>NUL
    
    Reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 8" >Nul
    If Not Errorlevel 1 (
    Dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase
    ) Else (
    Reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 8.1" >Nul
    If Not Errorlevel 1 (
    Dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase
    ) Else (
    Reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 10" >Nul
    If Not Errorlevel 1 (
    Dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase
    ) Else (	
    Goto :Event_Log
    ) ) )  
    
    Ping -n 4 localhost >Nul
    
    Goto :Event_Log
    
    
    
    
    :IsAdmin
    Reg query "HKU\S-1-5-19\Environment"
    If Not %ERRORLEVEL% EQU 0 (
     Cls & Mode CON  LINES=5 COLS=48 & Color 0C & Title - WARNING -
     Echo.
     Echo. 
     Echo  YOU MUST HAVE ADMINISTRATOR RIGHTS TO CONTINUE 
     Pause >Nul & Exit
    )
    Cls
    Goto :EOF
    
    
    
    :Event_Log
    Cls
    Mode CON  LINES=33 COLS=85
    For /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
    Echo.
    Echo                    Event Logs Have Been Cleared!
    Ping -n 5 127.0.0.1 >Nul
    Goto :eof
    :do_clear
    Echo clearing %1
    wevtutil.exe cl %1
    Goto :eof
    script to empty %temp% and Prefetch folders Attached Files
      My Computer


  4. Posts : 38
    windows 8.1
    Thread Starter
       #4

    thanks @Malneb. I appreciate your help if you can show me how to do that.
    We learn from each other.

    - - - Updated - - -

    thank you @FreeBooter. I would like to know if i have to delete from registry as well.
    Could you provide me with some explanation so i can understand how the commands are running and which folders are deleting please
      My Computer


  5. Posts : 5,347
    Windows 11 Pro 64-bit
       #5

    samerrustom said:
    thanks @Malneb. I appreciate your help if you can show me how to do that.
    We learn from each other.

    - - - Updated - - -

    thank you @FreeBooter. I would like to know if i have to delete from registry as well.
    Could you provide me with some explanation so i can understand how the commands are running and which folders are deleting please
    There is no registry values or keys been deleted by my batch script, it deletes temporary files and deletes files in Prefetch folder.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 02:11.
Find Us




Windows 10 Forums