Skip to content

Instantly share code, notes, and snippets.

@neremin
Last active June 17, 2024 22:27
Show Gist options
  • Save neremin/9c6905a0faedc98c6170153d56ee07b1 to your computer and use it in GitHub Desktop.
Save neremin/9c6905a0faedc98c6170153d56ee07b1 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