-1

I was just making this batch file which resets my phone completly! But I just wanted to know if I could stop it from running if any command dosnot run sucessfully. If it would still be ruunning commands it would probably hard brick my phone and none of us would like it to happen. So, how do I stop it??

ECHO Brought to you by Rocker223 @XDA
ECHO -__-__-__-__-__-__-__-__-__-__-
ECHO.
Echo     Motorolla MOTO G3(2015)
ECHO           Reset tool
ECHO -__-__-__-__-__-__-__-__-__-__-
cd /d %CD%
title Reset your mobile!
set p=0
ECHO ---Making sure your phone is in fastboot mode---
ECHO Press c to Cancel!
choice /c ync /M "Is your phone in fastboot mode"
if %errorlevel% == 2 ECHO Rebooting
if %errorlevel% == 2 adb reboot bootloader
if %errorlevel% == 3 exit(0)
title Flashing Partition file! Step:1 of 20
ECHO Flashing Partition file!
fastboot flash partition gpt.bin
title Flashing bootloader! 
ECHO Flashing bootloader!
fastboot flash bootloader bootloader.img
title Flashing Logo! Step:2 of 20
ECHO Flashing Logo!
fastboot flash logo logo.bin
title Flashing boot file! Step:3 of 20
ECHO Flashing boot file!
fastboot flash boot boot.img
title Flashing Recovery! Step:4 of 20
ECHO Flashing Recovery!
fastboot flash recovery recovery.img
set /a n=5
Title flashinng system image Step:%n% of 20
ECHO Flashing system image files might take a minute or two....
fastboot flash system system.img_sparsechunk.0
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.1
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.2
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.3
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.4
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.5
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.6
set /a n=n+1
Title flashinng system image Step:%n% of 20
fastboot flash system system.img_sparsechunk.7
set /a n=n+1
Title Finalising... Step:%n% of 20
ECHO Finalising...
fastboot flash modem NON-HLOS.bin
set /a n=n+1
Title Finalising... Step:%n% of 20
fastboot erase modemst1
set /a n=n+1
Title Finalising... Step:%n% of 20
fastboot erase modemst2
set /a n=n+1
Title Finalising... Step:%n% of 20
fastboot flash fsg fsg.mbn
set /a n=n+1
title Erasing Data... Step:%n% of 20
ECHO Erasing Data...
fastboot erase cache
set /a n=n+1
title Erasing Data... Step:%n% of 20
fastboot erase userdata
set /a n=n+1
title Rebooting your phone! Step:%n% of 20
ECHO Rebooting your phone!
fastboot reboot
title Finished!
ECHO All Done! Phone has been reset successfully!
Rocker2234
  • 11
  • 2
  • Take a look at http://stackoverflow.com/questions/734598/how-do-i-make-a-batch-file-terminate-upon-encountering-an-error – olikaf Jan 13 '17 at 11:01
  • Please read this: [mcve] – aschipfl Jan 13 '17 at 11:28
  • By the way: `exit(0)` is very interesting. You wrote a batch __script with command lines__ and NOT a __program with functions__. Run in a command prompt window `exit /?` for help on this command and right usage. I suggest to use `exit /B 0`. – Mofi Jan 13 '17 at 16:38

1 Answers1

0

You must check errorlevel after each command in the batch

Remus Rusanu
  • 273,340
  • 38
  • 408
  • 539