Page 1 of 1

How to detect in 7-Zip fatal error #2 "Wrong password" in windows batch?

Posted: 26 Jul 2023 07:17
by PiotrMP006
Hi

How to detect in 7-Zip fatal error #2 "Wrong password" in windows batch?

Code: Select all

ERROR: a.7z : Cannot open encrypted archive. Wrong password?

Re: How to detect in 7-Zip fatal error #2 "Wrong password" in windows batch?

Posted: 26 Jul 2023 08:05
by Batcher
test-1.bat

Code: Select all

@echo off
set "path=C:\Program Files\7-Zip;%path%"
7z a a.7z -pBatcher "C:\Program Files\7-Zip\7-zip.chm" >nul
7z x a.7z -pBatman 2>&1 | findstr /c:"Wrong password"
if not errorlevel 1 (
    echo Wrong password detected
)
pause

Re: How to detect in 7-Zip fatal error #2 "Wrong password" in windows batch?

Posted: 27 Jul 2023 04:07
by miskox
I tested it with 7za.exe (console version on 7zip website). If there is an error (maybe just wrong password or any other - can't tell - didn't check that) ERRORLEVEL was set to 2. If OK ERRORLEVEL was 0.

Code: Select all

7za.exe t -pWRONGPASS test.7z >nul 2>nul
echo %errorlevel%
Saso