|
改了下,换成当前目录了,输出log日志
我win7下测试正常
- @echo off
- setlocal enabledelayedexpansion
- cd /d "%~dp0"
- set "CurrentDir=%~dp0"
- set "WinSxSPath=%SystemDrive%\Windows\WinSxS"
- set "LogFile=%CurrentDir%\script_log.txt"
- echo Script started at %date% %time% > "%LogFile%"
- for /f "usebackq delims=" %%a in ("%CurrentDir%\ReserveWinSxS.txt") do (
- set "folderPattern=%%a"
- if not "!folderPattern!"=="" (
- echo Processing pattern: !folderPattern! >> "%LogFile%"
- for /f "delims=" %%i in ('dir /b "%WinSxSPath%" /ad ^| findstr /i /c:"!folderPattern!"') do (
- if exist "%WinSxSPath%\%%i" (
- echo Deleting: %%i >> "%LogFile%"
- takeown /f "%WinSxSPath%\%%i" /r /d y >> "%LogFile%" 2>&1
- icacls "%WinSxSPath%\%%i" /grant administrators:F /t >> "%LogFile%" 2>&1
- rd /s /q "%WinSxSPath%\%%i" >> "%LogFile%" 2>&1
- if %ERRORLEVEL% neq 0 (
- echo Failed to delete: %%i >> "%LogFile%"
- ) else (
- echo Successfully deleted: %%i >> "%LogFile%"
- )
- )
- )
- )
- )
- echo Script ended at %date% %time% >> "%LogFile%"
- endlocal
复制代码 |
|