Script to clear browser history and cache for IE, Firefox and Chrome

On your computer or laptop, you might need to clear browsing history and cache for IE, Firefox and Chrome, but you do manually most of the time.

But what if you can do this without manual click over and over, I will give you useful tricks that can help you to automate such task in background on your computer/laptop to clear the browsing history and cache for IE, Firefox and Chrome.

Internet Explorer (Powershell)-

$t_IE = "C:\Users\$env:username\AppData\Local\Microsoft\Windows\Temporary Internet Files"
$c_IE = "C:\Users\$env:username\AppData\Local\Microsoft\Windows\Caches"

$temporary_path =  Test-Path $t_IE
$check_cache =    Test-Path $c_IE
if($temporary_path -eq $True -And $check_cashe -eq $True)
    echo "Clean history"
    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

    echo "Clean Temporary internet files"
    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
    (Remove-Item $t_IE\* -Force -Recurse) 2> $null
    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

    echo "Clean Cache"
    (Remove-Item $c_IE\* -Force -Recurse) 2> $null

    echo "Done"

and save this file as “IE_clean.PS1” on your local machine.

Firefox (batch file)

@echo off
set DataDir=C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles
del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"
for /d %%x in (C:\Users\%USERNAME%\AppData\Roaming\Mozilla\Firefox\Profiles\*) do del /q /s /f %%x\*sqlite

And save this file as Firfox_clean.bat” on your local machine.

Chrome (batchfile)

@echo off
set ChromeDir=C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data
del /q /s /f "%ChromeDir%"
rd /s /q "%ChromeDir%"

Also save this file as “Chrome_clean.bat” on your local machine.

Now you have these all scripts ready to use when you want just double click on any selected script that you want to use based upon your browser but such repeated task you really do not want to do over and over.

Here we have supper simple method that you can use to automate this in Windows platform to do your job easy. You just need to put these scripts in your Start Program directory on your computer.

C:\Users\%UserName%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

These scripts will execute automatically and clear your previous browsering history and cache every time when you start or restart your machines.

Note- These script only useful on Windows Environment.


About Shachindra Yadav

I, Shachindra Yadav, a Cloud Certified, DevOps and technology enthusiastic person, more passionate to learn and write blogs in my free time.

View all posts by Shachindra Yadav →