Загрузка данных


Start-Sleep -Seconds 5

$mutex = New-Object System.Threading.Mutex($false, 'Global\FFCacheClean')
if (-not $mutex.WaitOne(60000)) { exit 0 }

try {
    $activeSids = @{}
    Get-CimInstance Win32_Process -Filter "Name='firefox.exe'" -ErrorAction SilentlyContinue |
        ForEach-Object {
            $r = Invoke-CimMethod -InputObject $_ -MethodName GetOwnerSid -ErrorAction SilentlyContinue
            if ($r -and $r.Sid) { $activeSids[$r.Sid] = $true }
        }

    $cacheNames = @('cache2','startupCache','jumpListCache','thumbnails','OfflineCache')

    function Clear-ProfileDir([string]$dir) {
        if (-not (Test-Path -LiteralPath $dir)) { return }
        foreach ($n in $cacheNames) {
            $t = Join-Path $dir $n
            if (Test-Path -LiteralPath $t) {
                Remove-Item -LiteralPath $t -Recurse -Force -ErrorAction SilentlyContinue
            }
        }
    }

    $profiles = Get-CimInstance Win32_UserProfile |
        Where-Object { -not $_.Special -and $_.LocalPath -and (Test-Path -LiteralPath $_.LocalPath) }

    foreach ($up in $profiles) {
        if ($activeSids.ContainsKey($up.SID)) { continue }

        $userHome  = $up.LocalPath
        $localFF   = Join-Path $userHome 'AppData\Local\Mozilla\Firefox'
        $roamingFF =