Unrar Error Code for Wrong Password
This article explains the specific exit status code returned by the
unrar utility when an extraction fails due to an incorrect
password. It details the primary error code introduced in modern
versions of the utility, highlights exceptions found in legacy formats,
and explains how to capture this status in automation scripts.
When a wrong password is provided to the unrar
command-line utility, it returns an exit status code of
11.
Exit Code 11: Wrong Password
In modern versions of RAR and unrar (version 5.0 and
newer), the utility specifically designates exit code 11 to
indicate an authentication failure. When an archive with encrypted
headers or encrypted file contents is accessed using an invalid
password, unrar terminates the operation and passes code
11 back to the operating system environment.
Legacy Behavior and Exceptions
While exit code 11 is the standard response for
incorrect passwords, specific conditions can yield different codes:
- Exit Code 3 (CRC Error): In older versions of
unrar(pre-5.0) or when extracting legacy RAR 2.x/4.x archives where headers are not encrypted, the utility may attempt extraction using the invalid key and fail during checksum validation. This results in exit code3(CRC error) instead of11. - Exit Code 2 (Fatal Error): If an incorrect password
causes the decryption process to fail catastrophically before the file
integrity check,
unrarmay fall back to exit code2.
Checking the Exit Code in Scripts
In automation environments such as Bash or shell scripts, you can
inspect the exit code immediately after executing the extraction command
using the $? variable:
unrar x -pwrongpass archive.rar
exit_code=$?
if [ $exit_code -eq 11 ]; then
echo "Extraction failed: Incorrect password provided."
elif [ $exit_code -eq 0 ]; then
echo "Extraction successful."
else
echo "Extraction failed with error code: $exit_code"
fiIn Windows Command Prompt or batch files, the equivalent variable is
%ERRORLEVEL%:
unrar x -pwrongpass archive.rar
if %ERRORLEVEL% EQU 11 (
echo Incorrect password.
)Monitoring for exit code 11 allows scripts to cleanly
distinguish between missing files, corrupt archives, and authentication
failures.