Batch file to compress WinSxS files that haven't been used in a while

2

2

I plan to compress unused files in the WinSxS directory because the directory is too big.

To do so I enabled tracking of last file access time (fsutil behavior set disablelastaccess 0). I'll use the PC normally for a few days, but will also try to use every program I occasionally use. Then I want to enable NTFS compression for all files in WinSxS that haven't been accessed in the last month.

To do this manually I need to change the owner, then grant permission to modify, then set compression attribute.

Does someone already have a reliable batch script that does this (going through files in C:/Windows/WinSxS/**/* last accessed before date, change permissions, and set compression attribute)?

Peter

Posted 2014-03-12T16:33:11.337

Reputation: 4 199

Question was closed 2014-07-04T19:59:16.560

1Hi Peter. 1) We aren't a script writing service, but we will help you if you get stuck. Where exactly are you getting stuck making the batch file you want? 2) whether is a "good" or "bad" idea depends on too many factors to make that an answerable question (IMO). Screwing with the WinSXS when you don't know what you're doing is ALWAYS a bad idea. :) – Ƭᴇcʜιᴇ007 – 2014-03-12T16:38:43.390

@techie007 definitely not a duplicate of that one. I'm not asking why it's large. I'm asking about how to do selective compression and about any known negative side-effects. – Peter – 2014-03-12T16:43:24.370

See this answer on that question http://superuser.com/a/8517/23133 for both techniques and comments/opinions as to if it's a good idea or not. Regardless of the possible dupe, as-is your question is too vague regarding the batch script help, and too opinion-based regarding if it's a 'bad idea' or not. But hey, takes more than my vote to close it. :)

– Ƭᴇcʜιᴇ007 – 2014-03-12T16:49:49.230

@techie007 Clarification: I'm not asking about opinions if this is a bad idea. I'm asking for concrete reasons why it might be a bad idea. I put that in here because I expected that I'd probably get a few answers of the "Don't do this altough I don't know why" type, but in retrospect I guess I should have left it out because it puts 2 questions into 1. Removed the 2nd question. – Peter – 2014-03-12T16:59:43.107

Generally answer to whether something is a good or bad idea is opinion-based. You can do whatever you'd like, if it works, then it's fine. ;) The problem existing now with what's left (as before) is that you are just asking for a script to do "X" - doing as such this is off-topic (you're just asking for a product). When it comes to script writing help, post what you've got already, point out exactly where you're getting stuck, and explain what you've tried already. – Ƭᴇcʜιᴇ007 – 2014-03-12T17:04:51.723

@techie007 Generally answer to whether something is a good or bad idea is opinion-based. - Often true. Which is why I never asked wether this is a good or bad idea. I asked people who would only point out that this is a bad idea to at least explain why. This comment thread derailed. I'll stop now. – Peter – 2014-03-12T17:10:02.747

You could compress it, but it will slow the heck out of your computer. – surfasb – 2014-03-12T17:17:49.623

"if this is a bad idea, please tell me why" does not sound like you know if it's a bad idea or not -- to me anyways. Btu yeah, this is derailed now. :) – Ƭᴇcʜιᴇ007 – 2014-03-12T17:26:23.353

Before this question is closed by overzealous voters: I'm not splitting the question into parts, because that would make it useless to other users. I'll probably need to write the answer myself so give me some time before close-voting it. – Peter – 2014-03-12T17:27:04.490

1

Run "dism.exe /online /cleanup-image /startcomponentcleanup" which does compression of unused files (http://superuser.com/a/594216/174557)

– magicandre1981 – 2014-03-12T19:38:27.710

have you tried the posted command to cleanup WinSxS? – magicandre1981 – 2014-05-24T05:36:45.317

Answers

2

Windows 8 already includes compression of unused files if you have the latest Servicing Stackup installed. Open a command prompt as admin and run this command:

dism.exe /online /cleanup-image /startcomponentcleanup

This removes all replaced Updates and compresses the files which can't be removed in a diff file which reduces the size a lot:

enter image description here

As you can see the NTFS.sys files of the updates which can't be removed are dramatically smaller compared to the NTFS.sys which is used.

magicandre1981

Posted 2014-03-12T16:33:11.337

Reputation: 86 560