[Guide] Write a batch script + ADB/Fastboot commands topic

SOCIALIZE IT ⇨

Write a batch script with ADB and Fastboot commands


1. Introduction:
Hi guys,
First of all, I've some words to say:
I've decided to make a tutorial for beginners how to write a windows batch file with ADB and Fastboot commands. I think it's quite easy and everybody can learn it.
My target is, that all of you can write your own batch files to control your device.
You don't need any knowledges about batch files or similar things. It's just helpful to know the adb commands and how they work.
I hope you'll understand every step, I make. The guide is splitted in several parts. :)

If you want, I'll add some more tips and tricks. :)


2. Requirements:




  • Windows Computer

  • Notepad++

  • ADB Tools

Just search on the internet for those files. They are easy to find.
  • Create a folder and place your adb/fastboot files in it. Make sure that they are working

  • Install Notepad++ on any place on your computer

  • Open Notepad++ and create a new file

  • Go to Languages -> Batch and activate it

  • Save the file as batch file in your adb folder

Well, I think now we can start with the main commands. :)







3. Main batch commands:




In this section, I'll explain you important main commands for your batch file.
Don't enter the quotationmarks in your file.

"@echo off" - Is always at the beginning of your file. This command blocks the output of your command in the cmd
"echo TEXT" - Here you enter "echo" and your text at the beginning of the line. This text appears in the cmd. E.g. : "echo Hello this is my first file"
"echo." - Will create a blank line
"pause" - Will create a pause in your file. The file continues by pressing any key. A message for that appears in the cmd
"pause>nul" - Has the same function like "pause" but you won't get the output in the cmd, that you need to press any key to continue
":TEXT" - Creates a certain section in your script
"goto TEXT" - This command brings you to the section "TEXT" in your code. "TEXT" can e.g. include any certain command, you want to execute


Declaration of variables:
Now I'll show you, how to declare a variable

"set test= Hello XDA-Members"
The variable "test" includes the string "Hello XDA-Members"
To access this variable, you need to enter %test%

"set /p input= Enter your variable:"
Here, the user needs to enter something in the cmd. This input will be saved in the variable "input".
To access this variable, you need to enter %input%
You can select the variable name as you want.


Now we have already some commands, so let's try them out.
In my example, I'll add comments to the commands, which are written in blue. Please don't add them to yours.
The second "@echo off" is not necessary




So, now we save the file and run it with a double-click.
Your script should look like this:
(Not everything is in mine included)





Making a selection menu:
Now, we make a selection meu where the user has several options

Step by step:
  • Create a list with "echo" commands

  • Create an input variable

  • Create an if statement


Let's take a look at my example code.
You should already understand the old commands. ;)




As you can see, this is still quite simple
If everything worked right, you should see this




Well, for the beginning that's enough. For the next step, you should know all these commands and how they work. :)





4. Including ADB/Fastboot commands:




Okay, now we'll start to add ADB and Fastboot commands to our batch file for controling our device with our tool.
The previous steps are the base for the following commands


First of all, we start with a quite easy command.
We want a batch file, which reboot our phone into Recovery,Bootloader or normal.
Now we need the adb files in our folder

Step by step:
  • Create a selection menu

  • Include the ADB/Fastboot commands


Let's take a look at my example code.
Our Reboot-Tool should look like this




These commands are still easy. You just need to enter your adb command
E.g.: adb.exe reboot recovery
Now we'll execute our file





You can see, that this tool is already very useful.
So, Congratulation to everybody who came so far
Are you ready for the next step? Let's go!





5. Including advanced ADB/Fastboot commands:




Okay, now we will add some more difficult commands to our script.
You need to know the old commands and how the work


Step by step:
  • Reboot device in different modes

  • Flash a custom recovery

  • Do a Factory Reset

  • Install Apps


Ok, let's take again a look at our example code
I won't explain the old commands, only the new ones.
Take your time and read it slowly.

The script is splitted in two pictures, so read both.







As you can see, we have now some more difficult codes, which include flashing Recoverys with certain file names. :)
Again, Congratulation who came so far.





6. Hints:




Now we are almost done with our first batch script.
At the end I have some more useful hints for you
  • Have always a clear structure

  • Take your time, it may not work for the first time

  • Read some other Batch-Guides on the internet

You can download the last script and the pictures from my dropbox:
https://www.dropbox.com/sh/jfogzlnj4...nuEmzON5a?dl=0

Moreover check out my Universal_ADB-Helper, which is based on this:
http://forum.xda-developers.com/andr...r-1-0-t2969165




7.Last words:




Now we are done with our batch script. I hope you enjoyed my tutorial and that it was easy to understand for beginners.
Moreover I want to say thank you at RootJunky who inspired me to start with batch scripting.

Check out this video from him:
https://www.youtube.com/watch?v=8q3y9zkEeHM

and his website:
http://www.rootjunky.com/



xda-developers


  1. [Script] CM 12/12.1 Debloater Script topic
  2. [Q] Class 10 SD card + INT2EXT script topic
  3. [battery] init.d script for battery life on stock topic
  4. [Q] can't write bootloader and i not have network Xperia Z topic
  5. Nand Write Start FAIL topic
  6. Write permissions in Lollipop topic
  7. [Q] Lollipop ROM failed to write external SDCard topic
  8. [Q] Can't write to External SD? topic
  9. [Q] Apps can't write into internal memory topic
  10. Anyway to get Viper4Android with write protection on? topic
  11. SGP611 external SD write access (Lollipop) topic
  12. "write permission on system partition are required in order to use..." on ArchiDroid topic
  13. Good news for Moto G owners with Chromebooks. MTP write support working in latest de topic
  14. [Q] Batch email delete topic
  15. [Guide] Write a batch script + ADB/Fastboot commands topic
  16. [Q] Commands not properly executing topic
  17. [Q] Google Now : Voice Commands : WiFi topic
  18. ZTE Blade Vec 4G - Guide - Links - FAQ - Discussion topic
  19. Boost Mobile (CDMA) Moto E 2015 Stock Firmware Restore Guide topic
  20. [Q&A] Guide For Making Android L Panel topic

0 commentaires:

Enregistrer un commentaire