Skip to content

How to Display a Confirmation Summary Before Executing Actions in Batch Script

Learn how to create a formatted execution preview in Windows batch scripts using variables, boxed summaries, and the choice command to safely confirm destructive actions before running.

One of the most dangerous things an automation script can do is perform destructive actions (like deleting files or wiping a registry key) without first confirming exactly what it "thinks" it is about to do. A Confirmation Summary provides a final overview of the variables and targets, giving the user one last chance to spot an error before the "Point of No Return."

In this guide, we will demonstrate how to build a formatted summary screen and use the choice command for the final execution trigger.

The Strategy: The "Audit" Phase

Before reaching the execution block of your script, you should:

  1. Gather all user inputs and environment variables.
  2. Format them into a clean, boxed summary.
  3. Pause and require a positive "Yes" to proceed.

Implementation Script: File Deployment Summary

@echo off
setlocal enabledelayedexpansion

:: 1. Simulation of variables set earlier in the script
set "source=C:\Projects\Marketing\Assets"
set "destination=\\FILESERVER\Public\2024"
set "fileCount=142"
set "action=OVERWRITE"
set "adminOnly=TRUE"

:: 2. Display the Summary Box
cls
echo ======================================================
echo             EXECUTION PREVIEW (SUMMARY^)
echo ======================================================
echo.
echo    SOURCE PATH:  !source!
echo    DESTINATION:  !destination!
echo.
echo    TOTAL FILES:  !fileCount!
echo    MODE:         !action!
echo    RESTRICTIONS: !adminOnly!
echo.
echo ======================================================
echo.

:: 3. The Final Confirmation
echo WARNING: The selected action is DESTRUCTIVE.
choice /c YN /m "Do you want to proceed with the execution?"

if !errorlevel! equ 2 (
    echo.
    echo [ABORT] Execution canceled by user.
    pause
    exit /b 1
)

:: 4. The actual action block
echo.
echo [RUNNING] Processing data...
:: (Actual commands go here)
pause
exit /b 0

Enhancing the Summary with ANSI Colors

On modern Windows 10 and later, using colors in your summary makes it much easier to read. Use yellow for paths and red for the mode.

@echo off
setlocal enabledelayedexpansion

:: 1. Simulation of variables set earlier in the script
set "source=C:\Projects\Marketing\Assets"
set "destination=\\FILESERVER\Public\2024"
set "fileCount=142"
set "action=OVERWRITE"
set "adminOnly=TRUE"

:: 2. Generate ESC character for ANSI codes
for /f %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
set "YL=!ESC![93m"
set "RD=!ESC![91m"
set "GN=!ESC![92m"
set "RS=!ESC![0m"

:: 3. Display the Summary Box with Colors
cls
echo ======================================================
echo             EXECUTION PREVIEW (SUMMARY^)
echo ======================================================
echo.
echo    SOURCE PATH:  !YL!!source!!RS!
echo    DESTINATION:  !YL!!destination!!RS!
echo.
echo    TOTAL FILES:  !GN!!fileCount!!RS!
echo    MODE:         !RD!!action!!RS!
echo    RESTRICTIONS: !adminOnly!
echo.
echo ======================================================
echo.

:: 4. The Final Confirmation
echo !RD!WARNING: The selected action is DESTRUCTIVE.!RS!
choice /c YN /m "Do you want to proceed with the execution?"

if !errorlevel! equ 2 (
    echo.
    echo [ABORT] Execution canceled by user.
    pause
    exit /b 1
)

:: 5. The actual action block
echo.
echo !GN![RUNNING]!RS! Processing data...
:: (Actual commands go here)
pause
exit /b 0

Why Every Script Needs a Summary

  1. Path Verification: It is easy to accidentally type C:\User instead of C:\Users. A summary allows the user to see the full path clearly before a del /q command runs.
  2. Environment Audit: If a script is sensitive to whether it is running on a "Production" or "Development" server, displaying the %COMPUTERNAME% in the summary is essential.
  3. Variable Visibility: Dynamic variables (like those generated by a for loop) can sometimes be empty if a previous step failed. The summary shows these empty values clearly.

Best Practices

  1. Use Boxes/Lines: Visual separators (like === or ***) help the user focus on the data rather than the surrounding console text.
  2. Explicit Abort: If the user chooses "No," always explicitly state [ABORT] so they aren't left wondering if the script finished anyway.
  3. Summary to File: For mission-critical tasks, append the same summary to a log.txt file before executing, so you have a record of what parameters were used.
  4. Formatting: Align the labels (e.g., SOURCE:, TARGET:) using spaces so they form a clean vertical column.
  5. Exit Codes: Return distinct exit codes (exit /b 0 for success, exit /b 1 for abort) so calling scripts or schedulers can detect the outcome.

Conclusion

A confirmation summary is the difference between a "reckless" script and a professional administrative tool. It adds a layer of human-in-the-loop safety that prevents catastrophic mistakes and builds user confidence. By taking the time to present your script's "plan" before execution, you ensure that your automation is both powerful and responsible.

Navigation