Had quite a close call with bricking my OpenPGP card which is specifically V2.0 .

To make it easier for those doing this in windows (mostly for myself). I made a batchfile that types the right commands into gpg to do a full factory reset of your OpenPGP card (Only tested on V2.0 btw, not V2.1 or V1.0), using codes from other sites (however most didn’t work, except this one after some corrections).

# ./FactResetOpenPGPCard.bat

@echo off
cd ./script
echo Type "I know what I am doing" if you want to reset card:
set /p word="passphrase: " %=%

SET TRIGWORD=I know what I am doing

IF "%word%" == "%TRIGWORD%" (gpg-connect-agent < openpgpcard_resetfile.scd) ELSE (echo incorrect passphrase)

PAUSE


# ./script/openpgpcard_resetfile.scd

/echo PURPOSE: To reset openpgp card (tested on V2.0 cards)
/echo to use (openpgpcard_resetfile.scd), type: gpg-connect-agent < openpgpcard_resetfile.scd
scd reset
scd serialno undefined
scd apdu 00 A4 04 00 06 D2 76 00 01 24 01
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 e6 00 00
scd reset
scd serialno undefined
scd apdu 00 A4 04 00 06 D2 76 00 01 24 01
scd apdu 00 44 00 00
/echo Card has been reset to factory defaults
/bye


# What went wrong before?

The issue is that many examples out there does not specify version, and the troublesome thing is that what may work on V1.0 may not work in V2.0

Also even when i got the correct set of codes, you must avoid trailing spaces when copying the apdu codes (Otherwise scd will get confused).

Once that is solved, it was just a matter of writing a batch file to make sure it works.