Saturday, March 26, 2011

bench3

How To Delete The WinSxS Folder

Before you go off and tell me that WinSxS is important to my OS's functionality...
I had a Windows 7 SP1 RC installation, which I sort of wrecked and I had to reinstall the OS over it. Of course, what happened was that the old Windows files were transferred to Windows.old. However, the WinSxS folder of the original installation remained, and lives on at eight gigabytes. When I tried deleting it, either from XP or from the new Win7 installation, I got "Access Denied" or "You Need Permission From TrustedInstaller" respectively.

TrustedInstaller owns the WinSxS folders, and I cannot change the ownership status. I can rename the folder, but not delete it. I have tried to use MoveFile to delete it on bootup, and I'm this close to installing a tiny Linux distributable just to try and delete the folder.  How do I delete this useless, space-eating folder?

To take ownership of the folder, right-click it, select Properties > Security Tab > Advanced at the bottom > Owner Tab > Edit > Highlight your username and put a tick in ‘Replace owner on sub containers…’ and Apply > OK. You will only have the ‘Replace owner on subcontainers…’ box for folders not files. Click Yes when you receive the Security pop-up window then click OK to the Close/Reopen message.

Now go back to the Properties > Security Tab. Click Edit > Add. Type in your User Account Name in the box under Enter the objects name to select. Click on Check Names > OK. Click on your User Account Name to highlight it. Check the box for Full Control > Apply and OK etc.

 

Here are some summarized points of what I understood about how all of it works.

To start by answering the question with the perfect answer posted above. Best advocie is not to touch winsxs. Maybe some of the files can be trimmed like the mp3's, avi's, etc but the rest of the system files should be left alone. I too am using Link Shell Extension as posted above by Ronnie Vernon, easy way to see which are hard linked (red arrow) and which are simple files.

Before getting here I saw in a lot of places people asking for the cleanup tool after installing SP1 for Windows 7 like vsp1cln. There is no dedicated tool, it all got integrated into the Disk Cleanup service. One note that I would make here is that even if the option says it will remove a few hundreds of MB after I cleaned up my drive the service removed around 3GB of excess files, so it varies from system to system. Funny, now I have even more space than I had before installing SP1. Nice one, MS.

Regarding the hard links, I got amused by the confusion created around them. I'm not a linux geek, and I usually use only soft links... they're enough for me, but people didn't get how the hard ones work and how size is counted.

A group of selected files, links or not, will always be counted as a sum. This means that if I take a 10MB file, and make 2 hard links, the selection of all three of them will have 30MB and this is the correct size, because unlike the soft links which are related to the file's original Master File Table entry and have 0 bytes, hard links are related to the data itself, have their own entry in MFT but point to the same data address, obviously having as size the size of the actual data, same times, attributes and so on. Why, below.

How much is left on the drive? Simple: exactly as much as the drive's own properties reports. Don't go selecting all the files, hidden and non hidden on C and making comparisons, or using tools that do that automatically because it won't show the actual HDD usage. Why? Because:

  1. That operation makes a list of all the selected files including hard links as separate files, takes each of them and adds the sizes up, the drives properties counts the actual stored data
  2. Not all the files will be counted, folders protected from traversing and files from reading will not be counted and the System Volume Information usually has very large files protected just in this manner
  3. That number is useful only in cases of file transfer, if the files, links, etc need to be copied to DVD or NAS, that's how much they would occupy, and the links will not be preserved since they are NTFS specific features, not available or available in different forms under ISO, UDF, NFS and other file systems, but they will be cloned.

Make a test... copy a 10MB file, a.exe, from a different drive and notice how the free space drops by the 10MB. Make a hard link (mklink /H b.exe a.exe). Now these two files selected will "use" 20MB in the selection properties, but actually only 10MB verified at the drive's properties, which will have the same free space as it did/does after the file copy. Delete one, either one, the free space will remain the same. Now delete the last one and the space will increase by 10MB. Was there any harm done? NO.

What is winsxs?

A much better dllcache. Where with the dllcache in XP we had copies of files that actually added to the size usage since they were cloned, this actually improves usage but not total protection (against viruses). If a rogue uninstaller thinks it has to remove some runtime libs from System32, it would only delete the links, but not the data, then the links would be recreated while keeping data space usage at lowest possible, better than archiving winsxs in cabs and having the cabs along side the original files. Also winsxs bring serialization, compartmentalizing files with the same name but different version, for the dev's sake, which is a good thing / bad thing, it makes them lazy to code properly but it helps when they don't want to code anymore.

I did this to help anyone that lands here out of the same reasons I did... excessive "usage of space" by winsxs after SP1. And I hope it was helpful.

bench3

About bench3 -

Haja Peer Mohamed H, Software Engineer by profession, Author, Founder and CEO of "bench3" you can connect with me on Twitter , Facebook and also onGoogle+

Subscribe to this Blog via Email :