2016-11-10 152 views
0

在磁盤清理工具中,有一個用於Windows Update清理的選項。如果我想通過以下方法設置它位於註冊表中的位置?註冊表編輯器中的Windows Update清理

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

如果我做/sageset:#我看到設置Windows更新清理的選項,但我一直無法找到它在註冊表編輯器。

回答

0

你可以得到可用VolumeCaches的列表,並設置爲全部Stateflag有:

# 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 
} 

但是你無法控制它在清理包括。有了這個腳本,你可以單獨編輯(縮短)列表。

#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 
} 

希望這有助於

0

通過運行磁盤清理經理的可執行文件Cleanmgr.exe,在命令行,你可以聲明清理輪廓。這些配置文件由可用處理程序的一個子集組成,並被賦予一個唯一的數字標籤。這使您可以在不同的時間自動運行不同組的處理程序。 命令行「cleanmgr.exe/sageset:nnnn」,其中nnnn是一個唯一的數字標籤,顯示一個UI,允許您選擇要包含在該配置文件中的處理程序。除了定義配置文件外,sageset參數還會將名爲StateFlagsnnnn的值(其中nnnn是您在參數中使用的標籤)寫入VolumeCaches下的所有子項。這些條目有兩種可能的數據值。 0:運行此配置文件時不要運行此處理程序。 2:運行此配置文件時包含此處理程序。 例如,假設運行命令行「cleanmgr.exe/sageset:1234」。在呈現的UI中,用戶選擇下載的程序文件,但不選擇臨時Internet文件。然後將以下值寫入註冊表。 HKEY_LOCAL_MACHINE 軟件 微軟的Windows CURRENTVERSION 瀏覽器 VolumeCaches Downloaded Program Files文件 StateFlags1234 = 0x00000002 Internet緩存文件 StateFlags1234 = 00000000 命令行 「cleanmgr.exe/SAGERUN:NNNN」,其中nnnn匹配的值用sageset參數聲明的標籤運行該配置文件中選定的所有處理程序。 磁盤清理正常運行時,通用StateFlags值被寫入註冊表。此值只是將處理程序的狀態(選中狀態或未選中狀態)最後一次作爲選項呈現給用戶。這些條目有兩種可能的數據值。 0:未選擇處理程序。 1:處理程序被選中。

另外Automate process of Disk Cleanup cleanmgr.exe without user intervention也討論了這一點。

謝謝,Tim。