清除 WinSxS 資料夾Clean Up the WinSxS Folder

本主題說明在執行中的 Windows 10 版本上縮減 WinSxS 資料夾大小的不同方式。This topic is about the different ways to reduce the size of the WinSxS folder on a running version of Windows 10.

其中一個常見問題是:「我可以刪除 WinSxS 資料夾以重新取得一些磁碟空間嗎?」One commonly asked question is, "Can I delete the WinSxS folder to regain some disk space?" 簡單的說,答案是「不可以」。The short answer is no. 不過,您可以使用 Windows 內建的工具來縮減 WinSxS 資料夾的大小。You can, however, reduce the size of the WinSxS folder using tools built into Windows. 如需 WinSxS 資料夾的詳細資訊,請參閱管理元件存放區For more information about the WinSxS folder, see Manage the Component Store.

除了內部程序以外,Windows 10 和 Windows Server 2016 也會使用與本主題中說明的類似方法自動縮減 WinSxS 資料夾的大小,例如,在套件中所含的元件已取代為其他新版元件時,將該套件解除安裝並刪除。Windows 10 and Windows Server 2016 automatically reduce the size of the WinSxS folder by using methods similar to the ones described in this topic, in addition to internal processes, such as uninstalling and deleting packages with components that have been replaced by other components with newer versions. 某些元件的舊版會在系統上保留一段時間,以供您在必要時進行復原。Previous versions of some components are kept on the system for a period of time, allowing you to rollback if necessary. 在這段時間結束後,這些較舊的元件就會自動從安裝中移除。After a period of time, these older components are automatically removed from the installation.

您也可以使用一些相同的技術來縮減 Windows 映像的大小,如減少離線 Windows 映像中的元件存放區大小中所說明。You can also reduce the size of a Windows image using some of the same techniques, as discussed in Reduce the Size of the Component Store in an Offline Windows Image.

若要了解如何確認您的 WinSxS 資料夾大小,請參閱判斷 WinSxS 資料夾的實際大小To learn about finding the size of your WinSxS folder, see Determine the actual size of the WinSxS folder.

警告

刪除 WinSxS 資料夾中的檔案或刪除整個 WinSxS 資料夾,可能會對系統造成嚴重損害,而導致您的電腦無法開機,也無法進行更新。Deleting files from the WinSxS folder or deleting the entire WinSxS folder may severely damage your system so that your PC might not boot and make it impossible to update.

  在 Windows 10 和 Windows Server 2016 中,您可以透過多種方式開始清除元件存放區,而搭配運用套件刪除和元件壓縮來清除 WinSxS 資料夾:In Windows 10 and Windows Server 2016, you have a number of ways to start the cleanup of the component store, which use a combination of package deletion and component compression to clean up the WinSxS folder:

工作排程器Task Scheduler

StartComponentCleanup 工作建立於 Windows 8 中,可在系統處於未使用狀態時自動定期清除元件。The StartComponentCleanup task was created in Windows 8 to regularly clean up components automatically when the system is not in use. 此工作會設定為在作業系統觸發時自動執行。This task is set to run automatically when triggered by the operating system. 自動執行時,此工作會在更新的元件安裝之後等候至少 30 天,再將舊版的元件解除安裝。When run automatically, the task will wait at least 30 days after an updated component has been installed before uninstalling the previous versions of the component.

如果您選擇執行此工作,此工作將會有 1 小時的逾時,而且可能不會完全清除所有檔案。If you choose to run this task, the task will have a 1 hour timeout and may not completely clean up all files.

在工作排程器中執行 StartComponentCleanup 工作,以清除和壓縮元件Run the StartComponentCleanup task in Task Scheduler to clean up and compress components

  1. 如果工作排程器未開啟,請啟動工作排程器If Task Scheduler is not open, start the Task Scheduler. 如需詳細資訊,請參閱啟動工作排程器For more information, see Start Task Scheduler.

  2. 展開主控台樹狀結構,並瀏覽至工作排程器程式庫\Microsoft\Windows\服務\StartComponentCleanupExpand the console tree and navigate to Task Scheduler Library\Microsoft\Windows\Servicing\StartComponentCleanup.

  3. 在 [選取的項目] 底下,按一下 [執行] Under Selected Item, click Run

    schtasks.exe /Run /TN "\Microsoft\Windows\Servicing\StartComponentCleanup"
    

    注意

    StartComponentCleanup 工作也可從命令列啟動。The StartComponentCleanup task can also be started from the command line.

Dism.exeDism.exe

Dism.exe/Cleanup-Image 參數未進階使用者提供了更多選項,讓他們可進一步縮減 WinSxS 資料夾的大小。The /Cleanup-Image parameter of Dism.exe provides advanced users more options to further reduce the size of the WinSxS folder. 如需詳細資訊,請參閱 DISM 作業系統套件服務命令列選項For more information, see DISM Operating System Package Servicing Command-Line Options.

使用 /StartComponentCleanup 參數Use the /StartComponentCleanup parameter

  • 在執行中的 Windows 10 版本上使用 Dism.exe 的 /StartComponentCleanup 參數,所產生的結果會類似於在工作排程器中執行 StartComponentCleanup 工作,差別在於,更新元件的舊有版本會立即刪除 (沒有 30 天的寬限期),且您不會有 1 小時的逾時限制。Using the /StartComponentCleanup parameter of Dism.exe on a running version of Windows 10 gives you similar results to running the StartComponentCleanup task in Task Scheduler, except previous versions of updated components will be immediately deleted (without a 30 day grace period) and you will not have a 1-hour timeout limitation.

    在提升權限的命令提示字元中,輸入下列命令:From an elevated command prompt, type the following:

    Dism.exe /online /Cleanup-Image /StartComponentCleanup
    

使用 /ResetBase 參數搭配 /StartComponentCleanup 參數Use the /ResetBase switch with the /StartComponentCleanup parameter

  • 在執行中的 Windows 10 版本上使用 /ResetBase 參數搭配 DISM.exe 的 /StartComponentCleanup 參數,會從元件存放區中移除每個元件所有已取代的版本。Using the /ResetBase switch with the /StartComponentCleanup parameter of DISM.exe on a running version of Windows 10 removes all superseded versions of every component in the component store.

    在提升權限的命令提示字元中,輸入下列命令:From an elevated command prompt, type the following:

    Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
    

    警告

    此命令完成後,就無法解除安裝所有現有的 Service Pack 和更新。All existing service packs and updates cannot be uninstalled after this command is completed. 這並不會封鎖未來 Service Pack 或更新的解除安裝。This will not block the uninstallation of future service packs or updates.

     

使用 /SPSuperseded 參數Use the /SPSuperseded parameter

  • 若要減少 Service Pack 所使用的空間量,請在執行中的 Windows 10 版本上使用 Dism.exe 的 /SPSuperseded 參數,以移除將 Service Pack 解除安裝所需的任何備份元件。To reduce the amount of space used by a Service Pack, use the /SPSuperseded parameter of Dism.exe on a running version of Windows 10 to remove any backup components needed for uninstallation of the service pack. Service Pack 是特定 Windows 版本的累積更新集合。A service pack is a collection of cumulative updates for a particular release of Windows.

    在提升權限的命令提示字元中,輸入下列命令:From an elevated command prompt, type the following:

    Dism.exe /online /Cleanup-Image /SPSuperseded
    

    警告   此命令完成後,就無法解除安裝 Service Pack。Warning   The service pack cannot be uninstalled after this command is completed.

     

磁碟清理Disk Cleanup

您可以使用「磁碟清理」來減少磁碟機上非必要檔案的數目,以利加快電腦的執行速度。You can use Disk Cleanup to reduce the number of unnecessary files on your drives, which can help your PC run faster. 此功能可刪除暫存檔案和系統檔案、清空資源回收筒,並移除您可能不再需要的各種其他項目。It can delete temporary files and system files, empty the Recycle Bin, and remove a variety of other items that you might no longer need. 清除更新的選項有助於縮減元件存放區的大小。The option to cleanup updates helps reduce the size of the component store.

執行磁碟清理以刪除系統檔案Run Disk Cleanup to delete system files

相關主題Related topics

管理元件存放區Manage the Component Store

判斷 WinSxS 資料夾的實際大小Determine the Actual Size of the WinSxS Folder

減少離線 Windows 映像中的元件存放區大小Reduce the Size of the Component Store in an Offline Windows Image

Uninstall-WindowsFeatureUninstall-WindowsFeature

如何使用功能隨選安裝在 Windows Server 2012 上縮減 Winsxs 目錄的大小及釋放磁碟空間How to Reduce the Size of the Winsxs directory and Free Up Disk Space on Windows Server 2012 Using Features on Demand

如何解決大型 Windows 元件存放區 (WinSxS) 目錄所造成的磁碟空間問題How to address disk space issues that are caused by a large Windows component store (WinSxS) directory