Matthew
Matthew

Reputation: 19

Windows Update Cleanup in Registry Editor

In the disk cleanup tool there is an option for Windows Update Cleanup. If I'm wanting to set it through the following method where is it located in the registry?

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files' -Name StateFlags0012 -Type DWORD -Value 2

If I do /sageset:# I see the option to set the Windows Update Cleanup, but I've been unable to find it in regedit.

Upvotes: 0

Views: 3854

Answers (2)

user6811411
user6811411

Reputation:

you could get a list of the available VolumeCaches and set to all a Stateflag with:

# Create reg keys
$StateFlags= "Stateflags0099"
$VolCaches = gci "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
foreach($VC in $VolCaches)
{
    New-ItemProperty -Path "$($VC.PSPath)" -Name $StateFlags -Value 2 -Type DWORD -Force | Out-Null
}

But you have no control which to include in the cleanup. With this script you may edit (shorten) the list individually.

#Requires -RunAsAdministrator

$SageSet = "StateFlags0099"
$Base = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\"
$Locations= @(
    "Active Setup Temp Folders"
    "BranchCache"
    "Downloaded Program Files"
    "GameNewsFiles"
    "GameStatisticsFiles"
    "GameUpdateFiles"
    "Internet Cache Files"
    "Memory Dump Files"
    "Offline Pages Files"
    "Old ChkDsk Files"
    "Previous Installations"
    "Recycle Bin"
    "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 ESD installation files"
    "Windows Upgrade Log Files"
)

ForEach($Location in $Locations) {
    Set-ItemProperty -Path $($Base+$Location) -Name $SageSet -Type DWORD -Value 2 -ea silentlycontinue | Out-Null
}

# do the cleanup . have to convert the SageSet number
$Args = "/sagerun:$([string]([int]$SageSet.Substring($SageSet.Length-4)))"
Start-Process -Wait "$env:SystemRoot\System32\cleanmgr.exe" -ArgumentList $Args -WindowStyle Hidden

# Removw the Stateflags
ForEach($Location in $Locations)
{
    Remove-ItemProperty -Path $($Base+$Location) -Name $SageSet -Force -ea silentlycontinue | Out-Null
}

Hope this helps

Upvotes: 1

Tim Haintz
Tim Haintz

Reputation: 676

By running the disk cleanup manager's executable file—Cleanmgr.exe—from a command line, you can declare cleanup profiles. These profiles are composed of a subset of the available handlers and are given a unique numeric label. This allows you to automate the running of different sets of handlers at different times. The command line "cleanmgr.exe /sageset:nnnn", where nnnn is a unique numeric label, displays a UI allowing you to choose the handlers to be included in that profile. As well as defining the profile, the sageset parameter also writes a value named StateFlagsnnnn, where nnnn is the label you used in the parameter, to all of the subkeys under VolumeCaches. There are two possible data values for those entries. 0: Do not run this handler when this profile is run. 2: Include this handler when this profile is run. For example, suppose that the command line "cleanmgr.exe /sageset:1234" is run. In the UI that is presented, the user chooses Downloaded Program Files, but does not choose Temporary Internet Files. The following values are then written to the registry. HKEY_LOCAL_MACHINE Software Microsoft Windows CurrentVersion Explorer VolumeCaches Downloaded Program Files StateFlags1234 = 0x00000002 Internet Cache Files StateFlags1234 = 0x00000000 The command line "cleanmgr.exe /sagerun:nnnn", where the value of nnnn matches the label declared with the sageset parameter, runs all of the handlers selected in that profile. A generic StateFlags value is written to the registry when Disk Cleanup is run normally. This value simply stores the state (checked or unchecked) of the handler the last time it was presented as an option to the user. There are two possible data values for those entries. 0: The handler was not selected. 1: The handler was selected.

Also Automate process of Disk Cleanup cleanmgr.exe without user intervention discusses this also.

Thanks, Tim.

Upvotes: 1

Related Questions