Skip to content

Instantly share code, notes, and snippets.

@andry81
Forked from neremin/winsxs_ntfs_compress.bat
Created December 2, 2023 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andry81/38d215c1d3757c9844cb854c70362e17 to your computer and use it in GitHub Desktop.
Save andry81/38d215c1d3757c9844cb854c70362e17 to your computer and use it in GitHub Desktop.
WinSxS folder compression script
@ECHO off
net session >nul 2>&1
IF %ERRORLEVEL% NEQ 0 GOTO ELEVATE
@GOTO ADMINTASKS
:ELEVATE
ECHO Elevated privileges are temporarily required to run script
cd /d %~dp0
mshta "javascript: var shell = new ActiveXObject('Shell.Application'); shell.ShellExecute('%~nx0', '', '', 'runas', 1); close();"
EXIT /B
:ADMINTASKS
REM Script to compress WINSXS folder
REM thanks to http://woshub.com
sc stop msiserver
sc stop TrustedInstaller
sc config msiserver start= disabled
sc config TrustedInstaller start= disabled
icacls "%WINDIR%\WinSxS" /save "%WINDIR%\WinSxS_NTFS.acl" /t
takeown /f "%WINDIR%\WinSxS" /r
icacls "%WINDIR%\WinSxS" /grant "%USERDOMAIN%\%USERNAME%":(F) /t
compact /s:"%WINDIR%\WinSxS" /c /a /i *
icacls "%WINDIR%\WinSxS" /setowner "NT SERVICE\TrustedInstaller" /t
icacls "%WINDIR%" /restore "%WINDIR%\WinSxS_NTFS.acl"
sc config msiserver start= demand
sc config TrustedInstaller start= demand
PAUSE
@ECHO on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment