Windows \ Temp大量cab_XXXX文件 – 无法删除

关于这个: Windows \ Temp大量的cab_XXXX文件

我无法删除这些文件。 我试图做一个移动删除,但有随机分散在那里被locking权限的文件。

我尝试以pipe理员身份运行PowerShell,但仍然给我权限问题。

有一个快速的方法来批量删除那里的所有cab_文件?

我喜欢当人们参考我的答案。 🙂

请先尝试停止受信任的安装程序服务。

这可能是因为这些文件是在正在运行的程序中打开的。 您可以尝试使用Windows中的“磁盘清理”实用程序来清除Temp文件夹。 如果在线时不起作用,请尝试启动进入安全模式并从那里删除它们。

我发现它有助于停止下面的代码中的三个服务。 我最初用另一种语言编写了帮助文本,翻译起来很麻烦,但是我添加了我为我的技术人员而不是技术人员提供的相关PowerShell代码,从记事本/任何东西粘贴到powershell.exe中,并逐步运行,半自动清理电脑文件生产失控的文件。 我正在翻译我现在发现的最相关的部分。

当一个CBSPersist日志成为大约1或2 GB大(我忘记了,认为是后者),并且makecab.exe试图压缩它,失败,并且在它本身之后不清理时,这可能发生(除其他事项外)并无限期地重复这一行动。

我们通过使用sysinternals进程监视器监视服务器来发现这一点。 如果我没有记错,这似乎是由Windows更新引发的。

这里的代码,希望它可以帮助别人。

# Ensure we have a C:\temp. No output (necessary, but if you know what you're doing, you can tweak ... ) $TempDir = 'C:\temp' if (-not (Test-Path -Path $TempDir -PathType Container)) { New-Item -ItemType Directory -Path $TempDir | Out-Null } Set-Location -Path $TempDir # Stop services. Lim inn disse tre linjene i powershell.exe og vent til den er ferdig. # it could take a couple of minutes Stop-Service -Name TrustedInstaller Stop-Service -Name wuauserv Stop-Service -Name BITS # Wait for makecab.exe to stop working, it seems to die by itself after # about a minute or three for me once you stop the services # if you want something to look at while waiting for makecab.exe to die. # you can also just look in task manager ... $ProcessToCheck = 'makecab' if (@(Get-Process -Name $ProcessToCheck -ErrorAction SilentlyContinue).Count -gt 0) { while (@(Get-Process -Name $ProcessToCheck -ErrorAction SilentlyContinue).Count -gt 0) { Write-Host -ForegroundColor Yellow "Waiting for ${ProcessToCheck}.exe to die ..." Start-Sleep 10 } } else { Write-Host -ForegroundColor Green "${ProcessToCheck}.exe is not running at all (anymore)." } Write-Host -ForegroundColor Green "${ProcessToCheck}.exe died, so you can continue." # Så skal vi slette cab_*_*-filene fra C:\Windows\Temp og vi er paranoide så vi vil se over # filene først for å verifisere. Kan hoppes over hvis du er verdensvant og sikker, antar jeg. # Lim inn alle disse linjene under i powershell.exe-vinduet og trykk enter (blank linje) til slutt. # Eller marker i PowerShell ISE og trykk F8. $TempCabFilesFile = "$TempDir\SIKT_Cab_Clean_temp.txt" $TempCBSFilesFile = "$TempDir\SIKT_CBS_Clean_temp.txt" Get-ChildItem -Path "${env:windir}\Temp\cab_*_*" | Select-Object LastWriteTime, @{n='Size (MB)'; e={[math]::Round(($_.Length / 1MB), 2)}}, FullName | Format-Table -AutoSize | Out-String -Width 1000 | Set-Content -Encoding utf8 -Path $TempCabFilesFile Get-ChildItem -Path "${env:windir}\Logs\CBS\cbspersi*.*" | Select-Object LastWriteTime, @{n='Size (MB)'; e={[math]::Round(($_.Length / 1MB), 2)}}, FullName | Format-Table -AutoSize | Out-String -Width 1000 | Set-Content -Encoding utf8 -Path $TempCBSFilesFile notepad $TempCabFilesFile notepad $TempCBSFilesFile # inspect the files that pop up (merk at det ene notepad-vinduet kan havne bak andre ting) # og sjekk at ikke noe som ikke skal slettes er med der. # If all appears well, we run the code from before, but also delete # sletter vi i tillegg. # Det som skal slettes er filer med navn cab_1234_56 (vilkårlige tall) og # CBSPersist_blabla.cab og -.log (.log kan være stor). # Hvis du er superparanoid, så kan du kjøre disse og se over (fjern "#" først). #Get-ChildItem -Path "${WinTempDir}\cab_*_*" | Remove-Item -WhatIf #Get-ChildItem -Path "${env:windir}\Logs\CBS\cbspersi*.*" | Remove-Item -WhatIf # This actually deletes the files! No output. Get-ChildItem -Path "${env:windir}\Temp\cab_*_*" | Remove-Item Get-ChildItem -Path "${env:windir}\Logs\CBS\cbspersi*.*" | Remove-Item # Start the services again, and run a wuauclt /detectnow # the latter sometimes fails, but it's not dangerous Start-Service -Name TrustedInstaller Start-Service -Name BITS Start-Service -Name wuauserv Start-Sleep 3 Start-Process -Wait -PassThru -FilePath wuauclt -ArgumentList '/detectnow' #### Usually not necessary #### # Try this if stuff appears broken. Can take a good while. Start-Process -Wait -PassThru -FilePath sfc -ArgumentList '/scannow' 

通过下载一个名为“Unlocker”的软件解决了这个问题,它允许你从内存中取消链接文件并删除它们。