CIS Remediation Batch Scripts NO SID

@echo off

setlocal enabledelayedexpansion

:: ========================================

:: Direct Registry File Processor

:: ========================================

:: This batch script processes Windows Registry files listed in a text file

:: by executing them directly without any modifications.

:: No SID replacement or processing is performed.

::

:: Usage: process_registry_direct.bat <file_list.txt>

:: Example: process_registry_direct.bat registry_files_list.txt

:: ========================================

:: Configuration - Edit this path as needed

set "REGISTRY_SOURCE_PATH=.\registry_files\"

:: Statistics

set "PROCESSED_COUNT=0"

set "FAILED_COUNT=0"

echo.

echo Direct Registry File Processor

echo ===============================

echo.

:: Check if file list parameter is provided

if "%~1"=="" (

echo ERROR: No file list specified.

echo Usage: %~nx0 ^<file_list.txt^>

echo Example: %~nx0 registry_files_list.txt

pause

exit /b 1

)

set "FILE_LIST=%~1"

:: Check if file list exists

if not exist "%FILE_LIST%" (

echo ERROR: File list "%FILE_LIST%" not found.

pause

exit /b 1

)

echo [%TIME%] INFO: Source path: %REGISTRY_SOURCE_PATH%

echo [%TIME%] INFO: File list: %FILE_LIST%

echo.

:: Read and display files to be processed

echo [%TIME%] INFO: Reading file list...

set "FILE_COUNT=0"

echo Registry files to be applied:

for /f "usebackq tokens=* delims=" %%a in ("%FILE_LIST%") do (

set "line=%%a"

:: Skip empty lines and comments

if not "!line!"=="" (

if not "!line:~0,1!"=="#" (

echo - !line!

set /a FILE_COUNT+=1

)

)

)

if !FILE_COUNT! equ 0 (

echo [%TIME%] WARN: No files to process

pause

exit /b 0

)

echo.

echo [%TIME%] INFO: Found !FILE_COUNT! files in list

echo.

:: Confirmation

set /p "CONFIRM=Do you want to apply these registry files? (Y/N): "

if /i not "!CONFIRM!"=="Y" (

echo [%TIME%] WARN: Operation cancelled by user

pause

exit /b 0

)

echo.

:: Process each file in the list

for /f "usebackq tokens=* delims=" %%a in ("%FILE_LIST%") do (

set "line=%%a"

:: Skip empty lines and comments

if not "!line!"=="" (

if not "!line:~0,1!"=="#" (

call :ApplyRegistryFile "!line!"

)

)

)

:: Summary

echo.

echo Processing Summary:

echo ==================

echo Files applied successfully: !PROCESSED_COUNT!

echo Files failed: !FAILED_COUNT!

set /a TOTAL_COUNT=!PROCESSED_COUNT!+!FAILED_COUNT!

echo Total files: !TOTAL_COUNT!

echo.

if !FAILED_COUNT! gtr 0 (

echo [%TIME%] WARN: Some files failed to apply

set "EXIT_CODE=1"

) else (

echo [%TIME%] SUCCESS: All files applied successfully

set "EXIT_CODE=0"

)

echo.

echo Operation completed.

pause

exit /b !EXIT_CODE!

:: ========================================

:: SUBROUTINES

:: ========================================

:ApplyRegistryFile

:: Apply a registry file directly without any processing

set "FILENAME=%~1"

set "SOURCE_FILE=%REGISTRY_SOURCE_PATH%%FILENAME%"

echo [%TIME%] INFO: Applying: %FILENAME%

:: Check if source file exists

if not exist "%SOURCE_FILE%" (

echo [%TIME%] ERROR: File not found: %SOURCE_FILE%

set /a FAILED_COUNT+=1

goto :eof

)

:: Apply the registry file directly

regedit /s "%SOURCE_FILE%"

if !ERRORLEVEL! equ 0 (

echo [%TIME%] SUCCESS: Successfully applied: %FILENAME%

set /a PROCESSED_COUNT+=1

) else (

echo [%TIME%] ERROR: Failed to apply: %FILENAME% - Error code: !ERRORLEVEL!

set /a FAILED_COUNT+=1

)

goto :eof

Next
Next

CIS Remediation Batch Script