If you run it as Admin, it will automatically clean system files.
Not quite. You still have to tick the boxes just not press the "cleanup system files" button.
That is why people do the cleanmgr /sageset:65535 & cleanmgr /sagerun:65535 as it saves ticking the boxes.
You can even script it to do the ones you want (if you didn't want it clear logs or empty the recycle bin or something).
I'd give credit for this script but I forgot who I copied it off.
Code:
$VName="StateFlags0032"
$DirPath="HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
# Folders Names which will been cleaned. Note some of these (for example "RetailDemo Offline Content") are deleted from
# the registry after first run. Messages like "Key not found" are therefore not important and can be ignored.
$TempFolders=@(
"Active Setup Temp Folders",
"BranchCache",
"Content Indexer Cleaner",
"Delivery Optimization Files",
"Downloaded Program Files",
"GameNewsFiles",
"GameStatisticsFiles",
"GameUpdateFiles",
"Internet Cache Files",
#"Memory Dump Files",
"Offline Pages Files",
"Old ChkDsk Files",
"Previous Installations",
#"Recycle Bin",
"RetailDemo Offline Content",
"Service Pack Cleanup",
"Setup Log Files",
"System error memory dump files",
"System error minidump files",
"Temporary Files",
"Temporary Setup Files",
"Temporary Sync Files",
"Thumbnail Cache",
"Update Cleanup",
"Upgrade Discarded Files",
"User file versions",
"Windows Defender",
"Windows Error Reporting Archive Files",
"Windows Error Reporting Queue Files",
"Windows Error Reporting System Archive Files",
"Windows Error Reporting System Queue Files",
"Windows Error Reporting Temp Files",
"Windows ESD installation files",
"Windows Upgrade Log Files")
Write-Host "The following are selected to be cleaned by cleanmgr" -f cyan
$error.clear()
For($i=0;$i -lt $TempFolders.Count; $i++) {
$RegKey=$DirPath + "\" + $TempFolders[$i]
$StateValue=(Get-ItemProperty $RegKey).$VName
If ($?) {
If ($Error.categoryinfo) {write-host "Key not found " -f red -NoNewline; write-host ": " $TempFolders[$i] -f White}
ElseIf (-not $StateValue) {
New-ItemProperty -Path $RegKey -Name $VName -Value "2" -PropertyType "dword" | out-null
write-host "Key added " -NoNewline; write-host ": " $TempFolders[$i] -f White
} Else {
Set-ItemProperty -Path $RegKey -Name $VName -Value "2"
write-host "Key updated " -NoNewline; write-host ": " $TempFolders[$i] -f White
}
$error.clear()
$RegKey=$DirPath
Write-Host "End of List" -f cyan
# 32 is a random number - just has to match $VName variable
CLEANMGR /sagerun:32
Write-Host "Disk Cleanup running asynchronously..." -f white