Courseiva
hardMultiple ChoiceObjective-mapped

220-1202 Practice Question: A company's login script uses a batch file that…

A company's login script uses a batch file that calls multiple other scripts. Recently, the script stopped working after a Windows update. The technician discovers that the script uses 'call' to run sub-scripts, but one of the sub-scripts contains an 'exit' command that terminates the entire batch process. How should the technician modify the sub-script to prevent this?

⚠ Common exam trap

CompTIA often tests the difference between 'exit' (terminates the entire command shell) and 'exit /b' (exits only the current batch script), leading candidates to mistakenly think 'exit' is always safe in sub-scripts.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Change 'exit' to 'exit /b'

The 'exit' command without parameters terminates the entire command interpreter (cmd.exe), which kills the parent batch file as well. Using 'exit /b' instead exits only the current batch script or subroutine, returning control to the calling script. This preserves the intended flow when sub-scripts are invoked via 'call'.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Replace 'exit' with 'goto :eof'

    Why it's wrong here

    While 'goto :eof' effectively terminates the current batch script and returns control to the calling process or command prompt, it does not explicitly set an ERRORLEVEL. In complex login scripts or chained batch files, the absence of a clear error code can make debugging difficult and prevent subsequent commands or scripts from reacting appropriately to success or failure conditions. 'exit /b' is preferred for its ability to return a specific exit code, providing better control flow and error handling.

  • Change 'exit' to 'exit /b'

    Why this is correct

    The 'exit /b' command is crucial for proper script execution within a larger context, such as a login script called by a system process or another batch file. It terminates only the current batch script, returning control to the calling script or process without closing the command interpreter window. This preserves the execution environment and allows subsequent commands in the calling process to run, which is essential for maintaining the integrity of a multi-stage login process.

  • Remove the 'exit' command entirely

    Why it's wrong here

    Removing the 'exit' command entirely from a batch file can lead to unintended consequences, especially if the script is designed to perform a specific task and then yield control. Without an explicit 'exit' command, the script will continue to execute any subsequent lines of code within the same batch file, or even commands in the calling environment if it was 'CALL'ed, potentially running commands that were not meant to be executed after the primary login script function is complete. This can introduce security vulnerabilities or operational errors.

  • Use 'endlocal' before 'exit'

    Why it's wrong here

    The 'endlocal' command is used to restore the environment variables to their state before the most recent 'setlocal' command was executed, effectively ending the localization of environment changes. While 'endlocal' is important for managing variable scope within a batch script, it has no direct impact on how the 'exit' command functions. 'exit' or 'exit /b' controls script termination, whereas 'endlocal' manages environment variable persistence, making their functions entirely separate and unrelated to the issue of proper script termination.

About these practice questions

Courseiva writes every 220-1202 question from scratch — 495 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 220-1202 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 220-1202 exam.