Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. @echo off
  2.  
  3. REM Script for compressing WinSXS files
  4. REM Compresses only files with 1 hard-link
  5. REM This means that file is old and is not used in system folders
  6. REM Special ln.exe is used because in Windows 2008 fsutil cannot show hardlinks...
  7.  
  8. REM by Daniel
  9.  
  10. REM ==============================================================================
  11.  
  12. REM First - we take over the folder
  13. REM takeown /A /R /F C:\Windows\winsxs\*
  14. REM icacls C:\Windows\winsxs\* /T /grant *S-1-5-32-544:(F^)
  15.  
  16. echo Taking over the folder: C:\Windows\winsxs
  17. echo ...running: takeown /A /R /F C:\Windows\winsxs\* ...
  18. REM test folder
  19. REM takeown /A /R /F C:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.0.6001.18000_en-us_bed98934da3d08ce\* >nul
  20. takeown /A /R /F C:\Windows\winsxs\* >nul
  21.  
  22.  
  23.  
  24. echo Adding permissions to Administrators
  25. echo ...running: icacls C:\Windows\winsxs\* /T /grant *S-1-5-32-544:(F^) ...
  26. REM test folder
  27. 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
  28. icacls C:\Windows\winsxs\* /T /grant *S-1-5-32-544:(F^) >nul
  29.  
  30.  
  31. REM AFTER !!!!
  32. REM run icacls C:\Windows\winsxs\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C
  33. REM run icacls C:\Windows\winsxs\* /reset >nul
  34.  
  35.  
  36.  
  37. REM Turn on environment variables parsing
  38. setlocal enabledelayedexpansion
  39.  
  40. echo Starting the main cycle...
  41.  
  42.  
  43. REM test folder
  44. REM for /R "C:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.0.6001.18000_en-us_bed98934da3d08ce" %%i in (*) do (
  45. for /R "C:\Windows\winsxs" %%i in (*) do (
  46.  
  47. REM Look for 1-line output
  48. REM fsutil hardlink list %%i | find /c /v "" | find /I "1" >nul
  49. REM And if there's 1 link, we compress the file
  50.  
  51. ln.exe --list %%i | find /i /v "ln 2." | find /c /v "" | find /I "1" >nul
  52. IF !ERRORLEVEL!==0 (
  53. Compact /C /A /I %%i >> log.txt
  54. )
  55. )
  56.  
  57.  
  58. echo Finished!!!
  59. echo .
  60.  
  61. REM Now restore permissions and ownership to TrustedInstaller
  62. REM icacls C:\Windows\winsxs\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C >nul
  63. REM icacls C:\Windows\winsxs\* /reset >nul
  64.  
  65. echo Restoring permissions
  66. echo ...running: icacls C:\Windows\winsxs\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C ...
  67. REM test folder
  68. 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
  69. icacls C:\Windows\winsxs\* /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 /L /C >nul
  70.  
  71. echo Restoring ownership
  72. echo ...running" icacls C:\Windows\winsxs\*
  73. REM test folder
  74. REM icacls C:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.0.6001.18000_en-us_bed98934da3d08ce\* /reset >nul
  75. icacls C:\Windows\winsxs\* /reset >nul
  76.  
  77.  
  78. @echo FINISH
  79. pause>nul
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement