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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PiotrMP006
Posts: 31
Joined: 08 Sep 2017 06:10

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

#1 Post by PiotrMP006 » 26 Jul 2023 07:17

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?

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

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

#2 Post by Batcher » 26 Jul 2023 08:05

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

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

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

#3 Post by miskox » 27 Jul 2023 04:07

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

Post Reply