用于在Windows上清除C​​hrome或Firefox缓存的脚本

时间:2014-08-08 18:49:51

标签: google-chrome powershell firefox windows-7 browser-cache

使用Internet Explorer,您可以创建.bat文件来清除缓存。

示例:

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

REM History:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

REM Cookies:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

REM Temp Internet Files:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

REM Form Data:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

REM Passwords:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32

REM OR

REM All:
rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351

有没有办法在Chrome和/或Firefox上执行此操作?

也就是说,使用在Windows计算机上运行的.bat文件或powershell脚本,清除Chrome或Firefox的缓存?

我保证,我已经看了。

3 个答案:

答案 0 :(得分:6)

在Chrome中,您可以通过删除%LocalAppData%\Google\Chrome\User Data\Default\Cache中缓存文件夹的内容来清除缓存。历史记录,cookie等是父文件夹中的SQLite数据库文件,所以如果你想要一切都消失,你也可以摆脱它们,就像在你的Internet Explorer示例中一样:

$Items = @('Archived History',
            'Cache\*',
            'Cookies',
            'History',
            'Login Data',
            'Top Sites',
            'Visited Links',
            'Web Data')
$Folder = "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default"
$Items | % { 
    if (Test-Path "$Folder\$_") {
        Remove-Item "$Folder\$_" 
    }
}

答案 1 :(得分:3)

Powershell杀死chrome并清除用户的所有chrome配置文件:

taskkill /F /IM "chrome.exe"
Start-Sleep -Seconds 5
$Items = @('Archived History',
            'Cache\*',
            'Cookies',
            'History',
            #'Login Data',
            'Top Sites',
            'Visited Links'
            #'Web Data'
            )
$Folders = Get-ChildItem "$($env:LOCALAPPDATA)\Google\Chrome\User Data" | ?{ $_.PSIsContainer -and $_.Name -eq "Default" -or $_.Name -like "Profile*"}
$Folders | ForEach-Object {
    $tmp = $_
    $Items | ForEach-Object { 
        if((Test-Path -Path "$tmp\$_" )){
            Remove-Item "$tmp\$_" 
        }
    }
}

答案 2 :(得分:2)

这是我的清理脚本变体,其中包含Eric脚本的改进版本。 它包括Chrome,Chromium和IE目录。
$DaysToDelete变量确定缓存数据存储在计算机上的天数。

$DaysToDelete = 1

$temporaryIEDir = "C:\users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" ## Remove all files and folders in user's Temporary Internet Files. 
$cachesDir = "C:\Users\*\AppData\Local\Microsoft\Windows\Caches"  ## Remove all IE caches. 
$cookiesDir = "C:\Documents and Settings\*\Cookies\*" ## Delets all cookies. 
$locSetDir = "C:\Documents and Settings\*\Local Settings\Temp\*"  ## Delets all local settings temp 
$locSetIEDir = "C:\Documents and Settings\*\Local Settings\Temporary Internet Files\*"   ## Delets all local settings IE temp 
$locSetHisDir = "C:\Documents and Settings\*\Local Settings\History\*"  ## Delets all local settings history

Get-ChildItem $temporaryIEDir, $cachesDir, $cookiesDir, $locSetDir, $locSetIEDir, $locSetHisDir -Recurse -Force -Verbose -ErrorAction SilentlyContinue | Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays(-$DaysToDelete)) } | remove-item -force -Verbose -recurse -ErrorAction SilentlyContinue

$DaysToDelete = 7

$crLauncherDir = "C:\Documents and Settings\%USERNAME%\Local Settings\Application Data\Chromium\User Data\Default"
$chromeDir = "C:\Users\*\AppData\Local\Google\Chrome\User Data\Default"
$chromeSetDir = "C:\Users\*\Local Settings\Application Data\Google\Chrome\User Data\Default"

$Items = @("*Archived History*", "*Cache*", "*Cookies*", "*History*", "*Login Data*", "*Top Sites*", "*Visited Links*", "*Web Data*")

$items | ForEach-Object {
$item = $_ 
Get-ChildItem $crLauncherDir, $chromeDir, $chromeSetDir -Recurse -Force -ErrorAction SilentlyContinue | 
    Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays(-$DaysToDelete)) -and $_ -like $item} | ForEach-Object -Process { Remove-Item $_ -force -Verbose -recurse -ErrorAction SilentlyContinue }
}