Android Batch Files

Share if the site was helpful

Android Batch Files & Scripts

First we need to understand what  batch files & Scripts do and how they work.  In DOS, OS/2, and Windows, a batch file is a type of script file, a text file containing a series of commands to be executed by the command line interpreter. For our purposes we will focus on Windows and Android specific commands.  Batch files were added to ease the work required for certain regular tasks by allowing the user to set up a script to automate them. When a batch file is run, the shell program (usually COMMAND.COM or cmd.exe) reads the file and executes its commands, normally line-by-line. In Windows this opens a command window to run the batch file.  Linux have a similar, but more flexible, type of file called a shell script.  The filename extension .bat is used in DOS and Windows while Linux uses .SH which is written in bash language. Now that you have some what of a understanding of what batch files and scripts are lets more to some example for Android and how Google even uses them.

ADB FASTBOOT

 

Above is a example of some commands to test if your device is connected and communicating with your computer correctly. run these from the command window.

 

ADB.EXE AND FASTBOOT.EXE

adb and fastboot are the application files that we as Android users reference and use. Adb is used when the android devices is on and booted up. While fastboot is used when the device is in bootloader or fastboot mode. HERE you will find a list of adb and fastboot commands commonly used with Android. But you can use batch files to do much more then Android commends this is just our focus for this post. once you put a list of these commands together in a text then just save it and change the extension to .bat and you have a batch file. If you want the adb and fastboot files you can get them HERE in a nice little zip.

Example from Google

@ECHO OFF
:: Copyright 2012 The Android Open Source Project

PATH=%PATH%;”%SYSTEMROOT%\System32″
fastboot flash bootloader bootloader-flounder-3.43.0.0114.img
fastboot reboot-bootloader
ping -n 5 127.0.0.1 >nul
fastboot -w update image-volantis-lrx21r.zip

echo Press any key to exit…
pause >nul
exit

This example is a Flash-All.bat file Google uses to restore the stock firmware to the Nexus 9

lets brake this batch file down.

@ECHO OFF = That means that every command issued in a batch file (and all of its output) would be echoed to the screen or in the command window. Note echo in front of words is never shown to the user when the batch file is run.

:: Copyright 2012 The Android Open Source Project = Just some written text for the user running the batch file to see

PATH=%PATH%;”%SYSTEMROOT%\System32″ = this is just setting up a system path not that important

fastboot flash bootloader bootloader-flounder-3.43.0.0114.img = use the fastboot.exe application to flash bootloader file named bootloader-flounder-3.43.0.0114.img. To break it down some more application fastboot.exe, command flash bootloader, and file bootloader-flounder-3.43.0.0114.img

fastboot reboot-bootloader = use the fastboot.exe application to reboot the bootloader

ping -n 5 127.0.0.1 >nul = Ping the bootloader to make sure it is visible to the batch script again.

fastboot -w update image-volantis-lrx21r.zip = use the fastboot.exe application to wipe the system and install the  image-volantis-lrx21r.zip to the device

echo Press any key to exit… =  Just some written text for the user running the batch file to see

pause >nul = stop the script and show the message above. ( Press any key to exit… )

exit = Just some written text for the user running the batch file to see

Batch files Explained

Simple Example

This example batch file displays “Hello World!”, prompts and waits for the user to press a key, and then terminates. (Note: It does not matter if commands are lowercase or uppercase unless working with variables)

@ECHO off
ECHO Hello World!
PAUSE

To execute the file, it must be saved with the extension .bat in plain text format, typically created by using a text editor such as Notepad++ or a word processor in text mode.

When executed, the following is displayed:

Hello World!
Press any key to continue . . .

If you really want to start to understand and even make your own batch files please download anyones tools scripts and rename the file extension from .bat to .txt and then open it in your favorite word processor and check out his or her work. I highly recommend NotePad++ its free and works great to editing and writing these batch files.

with all this info in mind check out these batch files

Examples from some of my batch files
::visit Rootjunky.com

::Set our Window Title
@title Amazon Fire TV Tool

::Set our default parameters
@echo off
color 0b

:menuLOOP

call:header
::Print our header
::call:header

::Load up our menu selections
echo.——————————————————————————–
for /f “tokens=1,2,* delims=_ ” %%A in (‘”C:/Windows/system32/findstr.exe /b /c:”:menu_” “%~f0″”‘) do echo. %%B %%C

call:printstatus

set choice=
echo.&set /p choice= Please make a selection or hit ENTER to exit: ||GOTO:EOF
echo.&call:menu_%choice%

GOTO:menuLOOP

:menu_1 Root Amazon Fire TV with Towel Root
cls
color 0b
echo.——————————————————————————–
echo. To root your Amazon Fire TV with Towelroot app click any
echo. key to continue and the files will be pushed to your deivce
echo.——————————————————————————–
pause
adb install towelrootV3.apk
adb install Superuser.apk
adb install Busybox Installer4.1.apk
echo. Root apps are now installed
echo. to launch app go to settings/applications
echo. run towel root app then run supersu
echo. and you are now rooted
echo.——————————————————————————–
echo. also recommend running busybox installer
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:menu_%choice%
color 0b
cls
GOTO:EOF

:menu_2 Install FiredTV launcher
cls
color 0b
echo.——————————————————————————–
adb install firedtvlauncher1.0.3.apk
echo. FiredTV laucher is now installed
echo. launcher it be pressing the home button
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:menu_%choice%
color 0b
cls
GOTO:EOF

:menu_3 Disable Fire TV OTA Updates ( Root Required )
cls
color 0b
echo.——————————————————————————–
echo. This will Disable OTA Updates on the Fire TV
echo.——————————————————————————–
pause
adb shell su -c “pm disable com.amazon.dcp”
echo. OTA Updates Disabled
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:menu_%choice%
color 0b
cls
GOTO:EOF

:menu_4 Install CWM Recovery ( Root & busybox Required )
cls
color 0b
echo.——————————————————————————–
echo. WARNING WARNING READ CAREFULLY
echo. Your Fire TV also needs to be running software version 51.1.0.2_user_510058520,
echo. 51.1.0.1_user_510055620, or 51.1.0_user_510047320. If it is not, then you will
echo. need to downgrade your Fire TV to version 51.1.0.2_user_510058520, but you can
echo. upgrade back up once the custom recovery is installed.
echo.——————————————————————————–
pause
adb push cwm-recovery.img /sdcard/
echo. CWM Recovery has been pushed to the Fire TV
echo. you may need to grant root to adb shell now
echo. on the Amazon Fire TV. you have 10 seconds to grant root or this will fail
adb shell su -c “dd if=/sdcard/cwm-recovery.img of=/dev/block/platform/msm_sdcc.1/by-name/recovery”
echo. CWM Recovery is now installed close program once CWM is on your screen
adb reboot recovery
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:menu_%choice%
color 0b
cls
GOTO:EOF

:menu_5 Firmware Downgrade/restore to 51.1.0.2 ( Root & busybox Required )
cls
color 0b
echo.——————————————————————————–
echo. This Requires Root and Busybox for it to work i have included
echo. the firmware and place it in this folder
echo. Firmware Version bueller-ota-51.1.0.2_user_510058520-signed.bin
echo. this is the firmware need to be able to install CWM recovery
echo. I highly recommend disabling ota updates before downgrading
echo. click any button to continue
echo.——————————————————————————–
pause
echo. you will need to grant root to adb shell now
echo. on the Amazon Fire TV
adb shell su -c “rm -f /cache/*.bin”
echo. cleaning up files for restore
adb shell su -c “rm -f /cache/*.zip”
adb shell su -c “rm -f /cache/recovery/command”
adb shell su -c “rm -f /sdcard/recovery.img”
echo. pushing stock recovery to device
adb push stock-recovery.img /sdcard/
adb shell su -c “chmod 777 /cache”
adb shell su -c “chmod 777 /cache”
adb shell su -c “chmod 777 /cache/recovery”
adb shell su -c “echo ‘–update_package=/cache/update.zip’ > /cache/recovery/command”
adb shell su -c “dd if=/sdcard/stock-recovery.img of=/dev/block/platform/msm_sdcc.1/by-name/recovery”
echo.——————————————————————————–
echo. sending update.zip to device this will take some
echo. time please wait depending on your network speed
adb push update.zip /cache
echo.——————————————————————————–
echo. if your Amazon Fire TV has booted to
echo. recovery and is installing update then
echo. it is safe to close this program
adb reboot recovery
timeout 8 > nul
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:menu_%choice%
color 0b
cls
GOTO:EOF
:menu_6 Partially unlock the botloader ( Root & busybox Required )
cls
color 0b
echo.——————————————————————————–
echo. This Requires Root and Busybox for it to work also must be on
echo. Firmware Version bueller-ota-51.1.0.2_user_510058520-signed.bin
echo. This will allow the bootloader to load things from boot or recovery without
echo. them needing to be patched. This is not a full unlock and will not enable
echo. fastboot boot or fastboot flash. Obviously this will only work if
echo. you are rooted.
echo. click any button to continue
echo.——————————————————————————–
pause
echo.——————————————————————————–
echo. you may need to grant root to adb shell now
echo. on the Amazon Fire TV
echo.——————————————————————————–
adb push aftv-unlock /data/local/tmp/
echo. pushing file to device
adb shell su -c “chmod 755 /data/local/tmp/aftv-unlock”
adb shell su -c “/data/local/tmp/aftv-unlock unlock”
echo.——————————————————————————–
echo. your device is now unlocked
echo.——————————————————————————–
timeout 8 > nul
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:menu_%choice%
color 0b
cls
GOTO:EOF
:header
cls
color 0e
echo.——————————————————————————–
echo. RootJunkys V4
echo. Firmwade Restore Tool brought to you by
echo. Rootjunky.com with help from Matt Groff.
echo. also firetv news for terminal commands.
echo.——————————————————————————–
echo.
adb kill-server
adb start-server
echo.——————————————————————————–
echo. First you must turn on ADB DEBUGGING in the fire tv settings
echo. Enter IP address from Amazon Fire TV in
echo. settings/system/about/network IP address number
echo. example 000.00.0.0 then press enter
echo.——————————————————————————–
echo Enter IP Number
set /p IP=””
adb connect “%IP%”
adb devices
timeout 8 > nul
cls
color 0b
GOTO:EOF

:printstatus
echo.
echo. Time to unlock the Beast
echo.——————————————————————————–
GOTO:EOF

 

Here is another one

::visit Rootjunky.com

::Set our Window Title
@title Tegra note 7 Super Tool

::Set our default parameters
@echo off
color 0b

:menuLOOP

call:header
::Print our header
::call:header

::Load up our menu selections
echo.——————————————————————————–
for /f “tokens=1,2,* delims=_ ” %%A in (‘”C:/Windows/system32/findstr.exe /b /c:”:menu_” “%~f0″”‘) do echo. %%B %%C

call:printstatus

set choice=
echo.&set /p choice= Please make a selection or hit ENTER to exit: ||GOTO:EOF
echo.&call:menu_%choice%

GOTO:menuLOOP

:menu_1 ADB & Fastboot Driver Install
cls
color 0b
adb kill-server
adb start-server
echo.——————————————————————————–
echo[*] This option will run a program to get your adb drivers
echo[*] installed for your Tegra Note 7 exit program when done
echo.——————————————————————————–
echo.
for /f “tokens=1,2,* delims=_ ” %%A in (‘”C:/Windows/system32/findstr.exe /b /c:”:driver_” “%~f0″”‘) do echo. %%B %%C
set choice=
echo.&set /p choice= Please make a selection then hit ENTER:
echo.&call:driver_%choice%
color 0b
cls
GOTO:EOF

:driver_1 Impactor driver install
cls
color 0b
echo.——————————————————————————–
echo [*] Before continuing, ensure USB debugging is enabled
echo [*] (device settings/about tablet click on build number 10 times
echo [*] back to settings/developer options enable usb debugging)
echo [*] MAKES SURE YOUR ANTI VERUS IS OFF.
echo.——————————————————————————–
echo [*] press any key to start adb driver install
pause >nul
echo.——————————————————————————–
echo [*] click USB, then [Drvier scan] to install the drivers
echo [*] once the adb drivers are install exit impactor
echo.——————————————————————————–
impactor\Impactor.exe
echo.——————————————————————————–
echo [*] Rebooting to bootloader to install fastboot drivers
echo.——————————————————————————–
adb reboot bootloader
echo.——————————————————————————–
echo [*] click USB, then [Drvier scan] to install the drivers.
echo [*] once the fastboot drivers are install exit impactor.
echo [*] recommend running the ADB driver test after this install
echo [*] some times a computer reboot is required to finish the driver install
echo.——————————————————————————–
impactor\Impactor.exe
echo [*] RootJunky OUT
fastboot.exe reboot

set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:bootsubmenu_%choice%
color 0b
cls
GOTO:EOF

:driver_2 ADB & Fastboot Driver Test
cls
color 0b
echo [*] Press any key to check if your drivers are installed
echo [*] correctly.
echo.——————————————————————————–
pause > nul
echo.——————————————————————————–
echo [*] Is there a device listed under list of devices attached?
echo [*] IF no then reboot computer and run the driver install option
echo [*] again then recheck
echo [*] press any key to continue
echo.——————————————————————————–
adb devices
pause > nul
adb reboot bootloader
echo.——————————————————————————–
echo [*] press any key to check fastboot drivers
pause > nul
echo.——————————————————————————–
echo [*] If you see a number with Fastboot after it your drivers are good
echo [*] IF no then reboot computer and run the driver install option
echo.——————————————————————————–
timeout 4 > nul
fastboot.exe devices
echo [*] press any key to reboot device
echo.——————————————————————————–
pause > nul
fastboot.exe reboot
echo [*] RootJunky OUT
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:bootsubmenu_%choice%
color 0b
cls
GOTO:EOF
:menu_2 Unlock Bootloader (this will factory reset your device)
cls
color 0b
adb kill-server
adb start-server
echo.——————————————————————————–
echo [*] Simple Tegra Note 7 Tool
echo [*] Windows Version
echo [*] Created by RootJunky.com
echo [*] I would recommend updating to android 4.3 before unlocking
echo.——————————————————————————–
echo [*] Before continuing, ensure USB debugging is enabled,
echo [*] (device settings/about tablet click on build number 10 times
echo [*] back to settings/developer options enable usb debugging)
echo [*] have the Nvidia drivers installed and your tablet
echo [*] connected via USB to the computer
echo [*] WARNING THIS WILL FACTORY RESET YOUR DEVICE
echo.——————————————————————————–
echo [*] Press any key to unlock your tablets bootloader…
pause > nul
echo [*] Waiting for device…
adb wait-for-device
echo [*] Device found.
adb reboot bootloader
echo.——————————————————————————–
echo [*] on the next screen you will have two options don’t unlock &
echo [*] unlock with volume buttons highlight unlock and select with
echo [*] power button. when its done you will be back in boot menu
echo [*] and it will say unlocked.
echo.——————————————————————————–
echo [*] Press any key to start
pause >nul
fastboot.exe oem unlock
echo.——————————————————————————–
echo [*] First boot will take up to 10 minutes and boot twice.
echo.——————————————————————————–
echo [*] press any key to reboot the device at this time.
pause > nul
fastboot.exe reboot
echo [*] RootJunky OUT
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:extrasubmenu_%choice%
color 0b
cls
GOTO:EOF

:menu_3 Restore Tegra Note 7 to Android 4.4.2 (unlocked bootloader required)
cls
color 0b
adb kill-server
adb start-server
echo.——————————————————————————–
echo [*] Restore to Android 4.4.2 KitKat latest ota
echo [*] After restore runs you can either wipe data or restart the device
echo [*] Before continuing, ensure your Tegra Note 7 is in the
echo [*] “Fastboot” mode and connected via USB with the drivers installed.
echo [*] From a powered off state, hold volume up and power to enter boot menu
echo [*] volume down to fastboot protocol and select with power.
echo.——————————————————————————–
echo [*] press any key to continue
pause > nul
fastboot.exe devices
fastboot.exe flash system 4.4.2-2.5system.img.ext4
fastboot.exe flash boot 4.4.2-2.5boot.img
fastboot.exe flash recovery 4.4.2-2.5recovery.img
echo.——————————————————————————–
echo. It is recommened to wipe data, especially if you were on a custom rom.
echo. If you don’t you will probably bootloop and have to wipe anyway…
echo.——————————————————————————–
echo.
for /f “tokens=1,2,* delims=_ ” %%A in (‘”C:/Windows/system32/findstr.exe /b /c:”:wipe_” “%~f0″”‘) do echo. %%B %%C
set choice=
echo.&set /p choice= Please make a selection then hit ENTER:
echo.&call:wipe_%choice%
color 0b
cls
GOTO:EOF

:wipe_1 WIPE DATA FACTORY RESET
cls
color 0b
echo [*] factory resetting device
fastboot.exe -w
echo. You are now on stock android 4.4.2 wiped clean
echo. Press any key to reboot the device. First boot will take up to 10 minutes.
pause > nul
fastboot.exe reboot
echo [*] RootJunky OUT
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:bootsubmenu_%choice%
color 0b
cls
GOTO:EOF

:wipe_2 REBOOT DEVICE
cls
color 0b
fastboot.exe reboot
echo [*] RootJunky OUT
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:bootsubmenu_%choice%
color 0b
cls
GOTO:EOF
:menu_4 Flash just stock android 4.4.2 recovery (unlocked bootloader required)
cls
color 0b
adb kill-server
adb start-server
echo.——————————————————————————–
echo [*] Before continuing, ensure USB debugging is enabled
echo [*] This will flash stock recovery to your
echo [*] device from fastboot then reboot back to system
echo.——————————————————————————–
echo [*] press any button to continue
pause > nul
echo [*] waiting for device
adb wait-for-device
echo [*] device found
adb reboot bootloader
fastboot.exe flash recovery 4.4.2-2.5recovery.img
fastboot reboot
echo [*] RootJunky OUT
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:bootsubmenu_%choice%
color 0b
cls
GOTO:EOF
:menu_5 Flash CWM recovery to recovery partition (unlocked bootloader required)
cls
color 0b
adb kill-server
adb start-server
echo.——————————————————————————–
echo [*] Before continuing, ensure USB debugging is enabled
echo [*] This will flash clockworkmod recovery
echo [*] to your device from fastboot.
echo.——————————————————————————–
echo [*] Press any button to continue
pause > nul
echo [*] waiting for device
adb wait-for-device
echo [*] device found
adb reboot bootloader
fastboot.exe flash recovery Bat-CWM-Recovery.img
echo.——————————————————————————–
echo [*] your device is on the boot menu screen. now scoll to Recovery
echo [*] Kernel with volume buttons and select with power to boot to recovery
echo.——————————————————————————–
echo [*] If you want to keep cwm recovery installed after
echo [*] a reboot select reboot system now and choose yes
echo [*] to keeping recovery and no to restoring root.
echo.——————————————————————————–
echo [*] RootJunky OUT
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:bootsubmenu_%choice%
color 0b
cls
GOTO:EOF
:menu_6 Flash TWRP recovery (unlocked bootloader required)
cls
color 0b
adb kill-server
adb start-server
echo.——————————————————————————–
echo [*] This will flash Team win / TWRP recovery
echo [*] to your device from fastboot.
echo.——————————————————————————–
echo [*] Press any button to continue
pause > nul
echo [*] waiting for device
adb wait-for-device
echo [*] device found
adb reboot bootloader
fastboot.exe flash recovery TWRP-Recovery.img
echo.——————————————————————————–
echo [*] your device is on the boot menu screen now scoll to Recovery
echo [*] Kernel with volume buttons and select with power to boot to recovery
echo.——————————————————————————–
echo [*] If you want to keep TWRP recovery installed after
echo [*] a reboot select reboot then system and choose yes
echo [*] to keeping TWRP recovery.
echo.——————————————————————————–
echo [*] RootJunky OUT
set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:bootsubmenu_%choice%
color 0b
cls
GOTO:EOF
:menu_7 Root your device (unlocked bootloader required)
cls
color 0b
adb kill-server
adb start-server
echo.——————————————————————————–
echo [*] Big thanks to ChainFire for supersu app
echo [*] Make sure USB Debugging is enabled on your tablet
echo [*] this will push Supersu and then temp boot into recovery.
echo [*] you will keep stock android recovery
echo.——————————————————————————–
echo [*] press any key to start
pause > nul
echo [*]
echo [*] waiting for device
adb wait-for-device…
adb push SuperSU-v2.02.zip /sdcard/download
echo.——————————————————————————–
echo [*] supersu is pushed to device press any key to enter recovery
echo.——————————————————————————–
pause > nul
adb reboot bootloader
Fastboot boot Bat-CWM-Recovery.img
echo [*]
echo.——————————————————————————–
echo [*] In recovery volume buttons are scroll and power is select
echo [*] select install zip, choose zip from sd card, 0, downloads,
echo [*] SuperSU-v2.00.zip, select yes install
echo [*] Select go back until you see reboot system now and select it
echo.——————————————————————————–
echo [*] Press any key to finish this script. ROOTJUNKY OUT

set choice=
echo.&set /p choice= hit ENTER to return to start: ||GOTO:EOF
echo.&call:bootsubmenu_%choice%
cls
GOTO:EOF
:header
cls
color 0e
echo.[//////////////////////////// ////////// //////////////////////]
echo.[/////////////////////////// /// ////////////// ///////////////////////////]
echo.[////////////////////////// //// ////////////// ////////////////////////////]
echo.[///////////////////////// // /////////////// /////////////////////////////]
echo.[//////////////////////// //// ///////// /// //////////////////////////////]
echo.[/////////////////////// ////// ///////// ////////////////////////////////]
echo. RootJunkys EVGA Nvidia Tegra Note 7 Super Tool 2.5 KITKAT
echo. Huge thanks to Matt Groff for his work on this device
echo.——————————————————————————–
echo.
adb kill-server
adb start-server
echo.——————————————————————————–
adb devices
timeout 5 > nul
fastboot devices
timeout 5 > nul
adb kill-server
cls
color 0b
GOTO:EOF

:printstatus
echo.
echo. Time to unlock the Beast
echo.——————————————————————————–
GOTO:EOF

 

Now go start making your own Android batch files 🙂 RootJunky Out….

Note: I am not a expert. I am learning along with everybody else.

Super Fans always leave a comment :-)

6 thoughts on “Android Batch Files

  1. Command.com??? When was this article written, the Bill Clinton administration? Pretty sure it’s been CMD.EXE since long before Android existed. And where’s the command line interpretater for Android? Or is it in fact command.com on Android (and a .com is an executable file on Android) and I simply haven’t heard of it till now.

  2. I created the batch file for android as per instructions here. I want to reboot my phone using the bat file I have created. But how do I run my batch file on my Android phone?
    I put my batch file in the ADB FASTBOOT FILES WINDOWS folder along with the other 4 files like adb and fastboot. Then i copied the entire ADB FASTBOOT FILES WINDOWS folder to the Internal storage of my phone and touched on my .bat file to run it.
    However, the phone is asking me which type of file is it, Audio, Video, Images or Document? I selected Document, so then it asks me which app I would like to open it with? Browser, HTML Viewer, WPS Office. Please help.

  3. Hi I’m trying to do a frp to an lg ms210 all the vids that I found online hasn’t help I’m thinking they probably fixed the batch on it is there any way u guys can help me out on this thanks in advance

Leave a Comment

Loading Facebook Comments ...