Windows optimize

Reduce the size of the WinSxS folder with vsp1cln.exe and compcln.exe

Deleting files from the Windows Side-by-side (WinSxS) folder is a bad idea. But, you can shrink the WinSxS folder with vsp1cln.exe and compcln.exe.

In last week's TR Dojo Challenge question, I asked TechRepublic members how do you safely reduce the size of the WinSxS folder. Before we get to the solution, let's get a little background on the Windows Side-by-side (WinSxS) folder.

Understanding Windows Side-by-side assemblies and the WinSxS folder

In an effort to combat the dynamically linked library (DLL) problems that plagued Windows 9x, Microsoft introduced the concept of Side-by-side (SxS) assemblies in Windows XP. DLL hell, as these problems were often referred to, occurred when multiple applications (let's say App. 1 and App. 2) relied on a single .DLL file. If App. 1 updated the .DLL file to a new version, but App. 2 still needed the old version, App. 2 might no longer work.

.LOCAL isolation and WinSxS in Windows XP

Prior to Windows XP (but also supported by XP), developers could use a process called .LOCAL isolation to prevent DLL conflicts. In a nut shell, .LOCAL isolation meant that applications would first look in the application directory for all the associated .DLL, .OCX, and .EXE files. If Windows didn't find the required file in the application directory, it would look for the file in other locations, such as the System32 directory. .LOCAL isolation could reduce DLL conflicts, but wasn't without drawbacks. First, installing multiple copies of the same shared .DLL file wastes disk space. Second, if a security vulnerability was discovered in a specific .DLL file, you would need to update every copy of that file, instead of just a single shared file. Windows Side-by-side was designed to address these problems.

When Windows XP was released, many developers were still supporting applications that had to run on previous Windows versions. It took several years, and the proliferation of Windows XP, for most developers to embrace the new methodology. On Windows XP machines, the WinSxS folder is only created if the user installs an application that uses it.

WinSxS in Windows Vista and beyond

With the release of Windows Vista, Windows Server 2008, and now Windows 7, Microsoft significantly expanded the role of the WinSxS folder. Unfortunately, Microsoft seems to provide two different descriptions of the WinSxS folder.

In a September 17, 2008 post on Microsoft's Ask the Core Team TechNet blog, Joseph Conway, Senior Support Escalation Engineer, described the WinSxS folder thusly:

"All of the components in the operating system are found in the WinSxS folder - in fact we call this location the component store.  Each component has a unique name that includes the version, language, and processor architecture that it was built for.  The WinSxS folder is the only location that the component is found on the system, all other instances of the files that you see on the system are "projected" by hard linking from the component store.  Let me repeat that last point - there is only one instance (or full data copy) of each version of each file in the OS, and that instance is located in the WinSxS folder. "

Yet in a November 29, 2008 post on Microsoft's MSDN blog, Michael Beck gave the following definition:

"In practice, nearly every file in the WinSxS directory is a "hard link" to the physical files elsewhere on the system-meaning that the files are not actually in this directory. For instance in the WinSxS there might be a file called advapi32.dll that takes up >700K however what's being reported is a hard link to the actual file that lives in the Windows\System32, and it will be counted twice (or more) when simply looking at the individual directories from Windows Explorer."

Taking his explanation a step further, Beck explains that because of this hard linking, Windows Explorer may misreport the actual size of the WinSxS folder. According to Beck:

"The Windows SxS directory represents the "installation and servicing state" of all system components. But in reality it doesn't actually consume as much disk space as it appears when using the built-in tools (DIR and Explorer) to measure disk space used. "

These descriptions seem to contradict each other. Conway asserts that the WinSxS folder is THE storage location for the files that Explorer reports it contains, which are then projected onto other locations. Beck seems to describe the WinSxS folder as containing mostly links (which Explorer treats as files) to physical files that actually exist in other directories. Luckily, this dichotomy has no impact on our efforts to reduce the size of the WinSxS folder.

Reducing the size of WinSxS

Regardless of whether the WinSxS directory is the physical repository for the actual component files or a collection of hard links to files stored across the drive, manually deleting files from this folder is a bad idea. Doing so could prevent applications from running and make the system unstable. So how do we reduce the size of the WinSxS folder--either as perceived by Explore or in actuality? There are three ways:

  1. Uninstall applications (possible)
  2. Use the vsp1cln.exe tool after installing Windows Vista SP1
  3. Use the compcln.exe tool after installing Windows Vista SP2

Uninstalling applications

Of the three methods I describe, I am least certain that this one will work. According to posts on Microsoft forums and around the Web, Windows Vista and later versions contain a "self scavenging" feature that will delete files from the WinSxS folder as they are replaced by newer versions or are no longer used. However, I have read just as many reports of the WinSxS folder remaining the same size even after users uninstalled applications or components. You'll just have to take your chances with this method.

Use vsp1cln.exe to clean up after Windows Vista SP1

One method that does seem to work is removing the redundant files left over after installing Windows Vista SP1. Thankfully, Microsoft provides the Windows Vista SP1 Files Removal Tool (vsp1cln.exe), which does just that. The tool is automatically installed as part of the SP1 upgrade, and you can find it at \%windir%\system32\vsp1cln.exe. I describe how to use the vsp1cln.exe in the TR Dojo video, "Remove all remnants of the Windows Vista SP1 installation files". Just make sure you're sticking with SP1 before running the tool, as you can't remove SP1 afterwards.

Use compcln.exe to clean up after Windows SP2

Just like cleaning up after SP1, you can use the Service Pack Clean-up tool (compcln.exe) to remove the files left over after installed Windows Vista SP2. Compcln.exe is an improved version of the earlier vsp1cln.exe tool. It is installed as part of the SP2 upgrade, and you'll find it at \%windir%\system32\compcln.exe. As with vsp1cln.exe, running compcln.exe will prevent you from removing SP2.

And the TechRepublic swag goes to...

This week's coffee mugs and laptop stickers to richardqt, who was first to mentioned vsp1cln.exe, and GreatZen, who provided an excellent description of the WinSxS folder, links to several relevant articles, and mentioned compcln.exe. Thanks to everyone who submitted an answer. If you don't see your answer here, be sure to give this week's question, "How do you prevent Windows from rebooting after an automatic update?" a try.

You can also sign up to receive the latest from the TR Dojo through one or more of the following methods:

For more information on the WinSxS folder, vsp1cln.exe and compcln.exe, check out the following resources:

About

Bill Detwiler is Managing Editor of TechRepublic and Tech Pro Research and the host of Cracking Open, CNET and TechRepublic's popular online show. Prior to joining TechRepublic in 2000, Bill was an IT manager, database administrator, and desktop supp...

12 comments
nota_bene_1
nota_bene_1

I have Vista SP2, When I run compcln.exe it is so fast that the cmd box closes before I can see what it has done (winsxs folder remains the same size so I guess it has failed.) As far as I can see, it outputs a line like 'cleaning windows components ...' and then finishes in a flash. Has anybody else had ths problem?

niente0
niente0

Here's the command to use for Windows Server 2008 and Windows 7: dism /online /cleanup-image /spsuperseded

whitc30
whitc30

This model is horrid. Firstly, in Windows Server 2008 the required hard disk size is 10GB, with a recommended 40GB drive in the Official Microsoft System requirements. I have many Windows 2008 servers. Due to security controls and best practices, we separate out different things to different partitions, and rarely do we budget a large amount of space for the boot partition. So we opted simply to use the recommended settings of 40GB. Had I known of this issue prior to installation I would have budgeted 150GB or so per server. Now I have over 100 local/remote servers with boot partitions that contain 10-15GB of unusable space (or duplicate space, however you want to explain it) that counts against the boot partitions of the drives. This is really unacceptable. 30% of my partition space is taken up with winsxs folders. But what is worse than that even is the addition it puts on backup/restore operations. In order to do a full system backup and not exclude this folder (because what does it mean if we do exclude it?) we are adding 1-1.5 TB to our backup requirements. Storage is cheap, but time isn't, and that extra processing time is a large net loss in the big scheme of things. Extremely poor design and implementation my Microsoft. EXTREMELY POOR!

Support Angel
Support Angel

As with all blogs, comments, explanations about this folder, nothing explains how to clean up this folder for W2k8...everything is in regards to Vista...what about Windows 7...

klapper
klapper

Great article, but I can't seem to find a utility for Server 2008. Does anyone know of one? The WinSxS directory on our 2008 SP1 server is almost 10GB, the total Windows directory size is about 16GB, and the partition is only 20GB. We tried installing SP2, but it requires at least 5GB of free space to install. 20GB is well within MS requirements for a 2008 installation. 20GB partition + 16GB Windows Directory + 10GB WinSxS Directory + 5GB Free Space Needed = SCREWED!

caducitate
caducitate

Could you please indicate if to your knowledge there is such an utility for 2008 Server (SP1)? thanks

jasonpeek00
jasonpeek00

my winsxs folder is 5.81 gigs currently how do you clean up on 7

crazy_driver_78
crazy_driver_78

[empathetic] yay, it reduced my winsxs folder from 16gb to 13gb

Mehul Bhai
Mehul Bhai

Are there any such utilities for Win XP and Win 7.

larryz
larryz

what tool do we use to clean up with XP SP3?

MrTintin
MrTintin

Win2k8 Std SP2 on our server which led us to this post. There is a CompCln.exe in System32. We had a WinSxS folder of 7.1GB and after running the exe it's down to 5.5GB. Not ideal, but a start - this could be due to the fact that the server is a temporary slash and burn and the build is 6002 - I assume, like Vista, this is SP2 Beta.

Lamini
Lamini

theres no such file in Server 2008 R2. I verified it was not there on SP1 either.... wonder why they removed it?! Unless that was a typo up there?? ("CompCln.exe)