Skip to main content

How to Create a Fake Error Message in a Batch Script

Creating a fake error message is a classic prank and a fun way to explore the capabilities of your batch scripting environment. While not a serious administrative task, it's a great way to learn about user interaction and how to mimic system dialogs. The goal is to create a pop-up window that looks like a real Windows error message, complete with an icon, custom text, and buttons.

This guide will teach you the standard and most effective method for creating a fake error message by having your batch script dynamically generate and execute a small VBScript file. You will learn how to customize the message box's title, text, buttons, and icon to create a convincing (and harmless) prank.

The Core Method: Using a Temporary VBScript

The cmd.exe command prompt is a text-only environment and cannot create graphical windows. To generate a pop-up, we must call a different part of the Windows operating system that can: the Windows Script Host (WScript.exe).

The easiest way to do this from a batch file is a simple, self-contained process:

  1. Write: Use ECHO commands to write a single line of VBScript code to a temporary .vbs file.
  2. Execute: Use wscript.exe to run the .vbs file. This will display the pop-up.
  3. Cleanup: Delete the temporary file.

The MsgBox Function: Your Tool for Creating Pop-ups

The VBScript MsgBox function is the key to this entire trick. It is designed to display a pop-up message box.

Syntax: MsgBox "Message Text", [Buttons+Icon], "Window Title"

  • Message Text: The main text that appears inside the box.
  • Buttons+Icon: A special number that defines the buttons and icon.
  • Window Title: The text that appears in the title bar of the pop-up window.

Basic Example: A Simple Fake Error

This script will create a simple but effective fake error message with just an "OK" button.

@ECHO OFF

REM --- Configuration ---
SET "ErrorMessage=Error: A fatal exception 0E has occurred at 0028:C0011E36 in VXD VMM(01) + 00010E36."
SET "ErrorTitle=System Error"
SET "VBSFile=%TEMP%\fake_error.vbs"

ECHO --- Launching Fake Error Message ---
ECHO.

REM --- Create the VBScript file ---
REM The '16' is the code for the critical "Stop Sign" icon.
ECHO MsgBox "%ErrorMessage%", 16, "%ErrorTitle%" > "%VBSFile%"

REM --- Execute the VBScript to show the pop-up ---
REM Using START /B makes the pop-up appear without the batch script waiting for it.
START /B wscript.exe "%VBSFile%"

ECHO The pop-up has been launched.

When run, this will display a convincing-looking system error pop-up.

Customizing the Error (Buttons and Icons)

You can make your fake error much more elaborate by combining button and icon codes.

Common Button Codes:

  • 0: OK
  • 1: OK and Cancel
  • 3: Abort, Retry, and Ignore
  • 4: Yes and No

Common Icon Codes:

  • 16: Critical (Stop sign icon) - Perfect for fake errors.
  • 32: Question mark icon
  • 48: Warning (Exclamation point icon)
  • 64: Information icon

You create the final code by adding the two numbers together. For example, an "Abort, Retry, Ignore" prompt (3) with a "Critical" icon (16) would use the code 3 + 16 = 19.

Making it Interactive: Capturing the User's "Choice"

A truly great prank gives the user a choice that has a funny or unexpected outcome. We can capture which button the user clicks by checking the ERRORLEVEL after the script returns.

Return Codes (ERRORLEVEL):

  • 1: OK
  • 2: Cancel
  • 3: Abort
  • 4: Retry
  • 5: Ignore
  • 6: Yes
  • 7: No

This script creates a fake error and then responds to the user's choice.

@ECHO OFF
SET "VBSFile=%TEMP%\interactive_error.vbs"

REM Create a VBScript with Abort, Retry, Ignore buttons (3) and a Critical icon (16). Code = 19.
ECHO WScript.Quit(MsgBox("System memory is low. Your data may be corrupt.", 19, "Memory Error")) > "%VBSFile%"

ECHO Launching interactive error...
cscript //nologo "%VBSFile%"

SET "UserChoice=%ERRORLEVEL%"
DEL "%VBSFile%"

IF "%UserChoice%"=="3" ECHO You clicked Abort. Okay, aborting...
IF "%UserChoice%"=="4" ECHO You clicked Retry. Retrying... (It will fail again!)
IF "%UserChoice%"=="5" ECHO You clicked Ignore. Ignoring the problem is a bold choice.
note

We use cscript here because it waits for the pop-up to be closed, allowing us to get the ERRORLEVEL immediately.

Practical Example: A "Critical Keyboard Failure" Prank

This is a classic prank script. It pops up an error that the keyboard is not responding and gives the user "Retry" and "Cancel" buttons. No matter what they click, it just pops up again, creating a frustrating (but harmless) loop.

@ECHO OFF
TITLE Harmless System Prank
SET "VBSFile=%TEMP%\keyboard_fail.vbs"

ECHO --- Prank Script Activated ---
ECHO Close this window to stop the prank.
ECHO.

:Loop
REM --- Create the VBScript with Retry/Cancel buttons and a Critical icon ---
ECHO WScript.Quit(MsgBox("Keyboard not responding. Press any key to continue.", 1 + 16, "Hardware Failure")) > "%VBSFile%"

REM --- Run the script and wait for the user's choice ---
cscript //nologo "%VBSFile%"

REM No matter what they click, we just loop back and show it again!
GOTO :Loop
note

The only way for the user to stop this is to close the main command prompt window.

Conclusion

Creating a fake error message is a fun way to learn about the power of hybrid scripting, where a batch file can control another scripting engine like VBScript to perform tasks it can't do on its own.

Key takeaways:

  • The core method is to have your batch script ECHO a MsgBox command into a temporary .vbs file.
  • You can customize the title, message, buttons, and icon using the numeric codes of the MsgBox function.
  • By using cscript.exe to run the .vbs file, your script can wait for the user's input and read the result from the %ERRORLEVEL%.