How to Clean Up and Compress WinSxS Folder in Windows 8

How to Clean Up and Compress WinSxS Folder in Windows 8

In this article we will talk about the WinSxS folder in Windows 8, the reasons of its constant growth and means of cleaning. The directory C:\windows\WinSxS is the storage of Windows components. This directory contains DLLs, binary and XML files necessary for installation and operation of any of Windows roles. When installing the OS updates, the new version of the updated component is installed in the system, while the old one is stored in the WinSxS storage (according to Microsoft, it is necessary to provide compatibility and make it possible to roll back to the old versions of components).
Contetn of WinSxS folder in windows 8
Another feature of the WinSxS folder is a huge amount of hard links in it. A hard link is a peer file pointer. That means that a pointer and a source file can have different names and are located in different directories of the same volume, but they point to the same object. It is due to hard links, taken into consideration when calculating the total size of the folder, that the file managers (including Windows Explorer) show a bit exaggerated size of the WinSxS folder. You can find out the real size of the WinSxS folder using du (small utility from Sysinternals):
 du -v c:\windows\winSXS
get winsxs folder real size with DU
Many users commonly ask if they can delete files from the WinSxS folder manually. The answer is categorically NO! These actions are likely to result in injuring the Windows 8 health. Though some attempts to remove files from the WinSxS folder can be successful, this means cannot be recommended due to its potential danger to the system.
Let’s dwell on the less harmful means of cleaning up the WinSxS folder in Windows 8. These are:
To reach the best result, you can use all three ways simultaneously.

Disk Cleanup Tool

Disk Cleanup Tool (cleanmgr) – which allows to delete deprecated updates (updates which were replaced with the newer ones).
 Tip.  This functionality is also available in Windows 7. Click here for details.

Features on Demand in Windows 8

In the article «Safe Clean Up of the WinSxS Folder in Windows Server 2012» we considered the new option Features on Demand, that allowed to remove binary files of the unused roles from the WinSxS folder. To remove the unused roles from the disk, there is a special PowerShell cmdlet – Uninstall-WindowsFeature. However, it’s not all as easy as it sounds in Windows 8. The thing is that there is no Uninstall-WindowsFeature cmdlet in Windows 8.  Features on Demand technology is based either on DISM or DISM PowerShell cmdlet. Moreover, it’s important to know that DISM command in contrast to Uninstall-WindowsFeature cmdlet doesn’t analyse package dependencies. So, after removing a Windows package using DISM only the component specified in the command will be removed and all dependent packages will stay in the system. This is the reason why DISM shouldn’t be used to remove roles from the disk in Windows Server 2012, since there is a more convenient and functional way to do it.
You can get the complete list of available functions in Windows 8 with the command:
DISM.exe /Online /English /Get-Features /Format:Table
get windows 8 feature list
Let’s suppose, for instance, that we won’t need TelnetServer role. Let’s delete it from the disk (from the WinSxS directory) completely using the command:
DISM.exe /Online /Disable-Feature /Featurename:TelnetServer /Remove
how to delete telnetserver feature in windows 8
If you display the list of all functions available in Windows 8, you can see that the component status has changed to Disabled with Payload Removed.
Thus, Windows 8 allows to significantly reduce the size of the WinSxS folder by removing the unused components from the disk. The only thing is that this cleanup method suits only advanced users, who know what this or that component does in Windows 8.

Compressing the Contents of the WinSxS Folder in Windows 8

Another way to reduce the size of the WinSxS directory in Windows 8 is to compress the directory contents on the level of the NTFS file system.
  NoteAs in case of any nonstandard intervention into the system configuration, you are strongly recommended to perform a full system backup.
    1. Open the command prompt as administrator
    2. Stop and disable Windows Installer and Windows Module Installer
      sc stop msiserver
      sc stop TrustedInstaller
      sc config msiserver start= disabled
      sc config TrustedInstaller start= disabled
    3. Let’s back up the access lists (ACLs) assigned to the files and folders in the WinSxS directory (this backup will become necessary when recovering original ACLs)
      icacls "%WINDIR%\WinSxS" /save "%WINDIR%\WinSxS_NTFS.acl" /t
      icacls - backup winsxs ACL
    4. Assign yourself as an owner of the WinSxS folder and all its subfolders
      takeown /f "%WINDIR%\WinSxS" /r
    5. Grant your account full rights on the WinSxS directory
      icacls "%WINDIR%\WinSxS" /grant "%USERDOMAIN%\%USERNAME%":(F) /t
    6. Compress the WinSxS directory and its contents with the command compact. Some files can be used by the system, so if you run this command without /i, the compression will stop at the first file currently used by the system. You can find the name of the process that has opened this file (CTRL+F) and stop it with Process Explorer. Thus you can achieve maximum compression ratio. We will confine ourselves to the compression of the unused files.
      compact /s:"%WINDIR%\WinSxS" /c /a /i *
      compress winsxs folder with compact utility
    7. Change the WinSxS directory owner back to TrustedInstaller
      icacls "%WINDIR%\WinSxS" /setowner "NT SERVICE\TrustedInstaller" /t
    8. Recover original ACLs to the WinSxS directory
      icacls "%WINDIR%" /restore "%WINDIR%\WinSxS_NTFS.acl"
      winsxs ntfs compress complited
    9. Recover the startup of Windows Installer and Windows Module Installer
      sc config msiserver start= demand
      sc config TrustedInstaller start= demand
Now check the size of the WinSxS folder:
size of winsxs folder
As you can see, in our example after the compression the size of the WinSxS folder has reduced from5.8GB to 4GB (approximately by 1/3). Not bad, especially taking into consideration that the compression took place for a small SSD with free space highly appreciated.

What Can WinSxS Reduction Influence on?

Windows 8 works with compressed files in the transparent mode. However, it can take some extra time to compress/decompress it, which means that the component or update installation processes can become somewhat slow. But the modern CPU performs these processes almost instantaneously, so a user can see no difference in speed. On top of that, if a hard drive is slow and a CPU is fast enough, you can observe even the increase in the speed of operation! We should note that when the whole contents of the WinSxS folder is compressed, a number of files in some other system directories will also turn to be compressed due to the hard links.
These commands can either be run separately (then it is much easier to control the results of each of them) or used in a single script file. If you run it, the described compression procedure of the WinSxS folder will start. You can download the ready-to-use command file here: winsxs_ntfs_compress.bat
This script can be used regularly during system operation, because after new updates or applications have been installed, new uncompressed files will appear in the WinSxS folder.
  NotesYou can find in the web another script that allows to reduce the size of the WinSxS folder— WinSxSLite (by Christian Bering Boegh). According to the developer, this script searches the latest library files on the disk, makes links to them from all previous versions and deletes old versions. We do not recommend our readers to use WinSxSLite, because in spite of the idea being good, the result of running the script is unpredictable and though the WinSxS folder is reduced, some Windows 8 functionality becomes unavailable.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s