Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- REM Script for compressing WinSXS files
- REM Compresses only files with 1 hard-link
- REM This means that file is old and is not used in system folders
- REM Special ln.exe is used because in Windows 2008 fsutil cannot show hardlinks...
- REM by Daniel
- REM ==============================================================================
- REM First - we take over the folder
- REM takeown /A /R /F C:\Windows\winsxs\*
- REM icacls C:\Windows\winsxs\* /T /grant *S-1-5-32-544:(F^)
- echo Taking over the folder: C:\Windows\winsxs
- echo ...running: takeown /A /R /F C:\Windows\winsxs\* ...
- REM test folder
- REM takeown /A /R /F C:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.0.6001.18000_en-us_bed98934da3d08ce\* >nul
- takeown /A /R /F C:\Windows\winsxs\* >nul
- echo Adding permissions to Administrators
- echo ...running: icacls C:\Windows\winsxs\* /T /grant *S-1-5-32-544:(F^) ...
- REM test folder
- REM icacls C:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.0.6001.18000_en-us_bed98934da3d08ce\* /T /grant *S-1-5-32-544:(F^) >nul
- icacls C:\Windows\winsxs\* /T /grant *S-1-5-32-544:(F^) >nul
- REM AFTER !!!!
- REM run icacls C:\Windows\winsxs\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C
- REM run icacls C:\Windows\winsxs\* /reset >nul
- REM Turn on environment variables parsing
- setlocal enabledelayedexpansion
- echo Starting the main cycle...
- REM test folder
- REM for /R "C:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.0.6001.18000_en-us_bed98934da3d08ce" %%i in (*) do (
- for /R "C:\Windows\winsxs" %%i in (*) do (
- REM Look for 1-line output
- REM fsutil hardlink list %%i | find /c /v "" | find /I "1" >nul
- REM And if there's 1 link, we compress the file
- ln.exe --list %%i | find /i /v "ln 2." | find /c /v "" | find /I "1" >nul
- IF !ERRORLEVEL!==0 (
- Compact /C /A /I %%i >> log.txt
- )
- )
- echo Finished!!!
- echo .
- REM Now restore permissions and ownership to TrustedInstaller
- REM icacls C:\Windows\winsxs\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C >nul
- REM icacls C:\Windows\winsxs\* /reset >nul
- echo Restoring permissions
- echo ...running: icacls C:\Windows\winsxs\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C ...
- REM test folder
- REM icacls C:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.0.6001.18000_en-us_bed98934da3d08ce\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C >nul
- icacls C:\Windows\winsxs\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C >nul
- echo Restoring ownership
- echo ...running" icacls C:\Windows\winsxs\*
- REM test folder
- REM icacls C:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.0.6001.18000_en-us_bed98934da3d08ce\* /reset >nul
- icacls C:\Windows\winsxs\* /reset >nul
- @echo FINISH
- pause>nul
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement