Skip to content

Instantly share code, notes, and snippets.

@thebagchi
Last active December 28, 2021 05:29
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save thebagchi/df29ae862fc1c296dec2 to your computer and use it in GitHub Desktop.
Save thebagchi/df29ae862fc1c296dec2 to your computer and use it in GitHub Desktop.
script for issuing commands to multiple android devices on windows
:: Inspired by Linux version of the same https://gist.github.com/christopherperry/3208109
@echo off
SET ARGUMENTS=%~1
if "%ARGUMENTS%" == "" (
GOTO EOF
)
SET "ARGUMENTS=%ARGUMENTS:""="%"
SETLOCAL ENABLEDELAYEDEXPANSION
:: INSTALL ON ALL ATTACHED DEVICES ::
FOR /F "tokens=1,2 skip=1" %%A IN ('adb devices') DO (
SET IS_DEV=%%B
if "!IS_DEV!" == "device" (
SET SERIAL=%%A
echo "adb -s !SERIAL! %ARGUMENTS%"
call adb -s !SERIAL! %ARGUMENTS%
)
)
ENDLOCAL
:EOF
@DevilSquad
Copy link

Hi,
Can you explain me more about your software ?. I need to install and use other ADB command on multiple devices. I have a hub that connects to multiple android devices. I want to install the APK file on all devices.

@thebagchi
Copy link
Author

Hi,

You can run this bat file on windows if you have adb installed.

adb+.bat install app.apk

This command will install app.apk on all the connected devices.

If you want to select device then you can use adb++.bat

@smelfungus
Copy link

Thank you for solution. Here is a version to execute shell commands in the same way:
https://gist.github.com/DummyCo/f3cc57a8f564baf5ba88fd16c5bae85e

@vpkhachane
Copy link

Getting this error
'adb+.bat' is not recognized as an internal or external command,
operable program or batch file.

@pieceofquality
Copy link

something wrong in you script
when i make command "ADB+ install test.apk"in console appears response without apk...

"adb -s 192.168.182.101:5555 install"
Android Debug Bridge version 1.0.36
Revision e02fe72a18c3-android

-a - directs adb to listen on all interfaces for a connection
-d - directs command to the only connected USB device

Can you help with that?

@cmfsotelo
Copy link

cmfsotelo commented Nov 8, 2016

Hi @pieceofquality
try changing the second line (after the @echo off) to
SET ARGUMENTS=%*
That solved it for me.

PS: @thebagchi Thanks for the script ;)

@michaelkmatific
Copy link

Thank you for the script!

@yossigrosskopf
Copy link

Thanks for this Great script

I am trying to create a .bat file to run a few commands
Problem I have is after it runs the first command it closes the window

Example:
main\adb+ install app-debug.apk
main\adb+ uninstall com.alphabetlabs.deviceinfo

Any help would be greatfull

@AtomicDragon
Copy link

Thanks for the script!

@probsJustin
Copy link

I am looking forward to working with this script thank you.

@harishravi6293
Copy link

My Requirement:

  1. Need to install/uninstall apk in multiple devices
  2. Devices list will be vary to every time.
  3. How to install the apk in multiple devices in all the time without giving any device id manually
  4. Need automation script for this.

Please confirm below script is good one to install apk in multiple devices on windows machine!!
Also, please share the steps in detailed manner to run this.

echo off
setlocal EnableDelayedExpansion
for /f "tokens=" %%f in ('C:\android\sdk\platform-tools\adb.exe devices') do (
for /r %%p in (
.apk) do (
set devicestr=%%f
set apk=%%p
if "!devicestr!"=="!devicestr:List=!" (
for /f "tokens=1" %%d in ("!devicestr!") do (
set deviceid=%%d
echo !deviceid!
echo !apk!
C:\android\sdk\platform-tools\adb.exe -s !deviceid! install !apk!
)
)
)
)

@harishravi6293
Copy link

Also need instructions for how to save this BAT file?

@bhargis
Copy link

bhargis commented Dec 10, 2020

I realize this is a bit old, but I am seeing issues here. Maybe I am missing something.

'adb devices' is returning a list of devices, but when I call this batch file nothing is seen. I am even trying to echo out IS_DEV and nothing is there. Digging in deeper 'adb devices > dev.txt' and dev.txt is empty.

@thebagchi
Copy link
Author

Please check

  • device is connected
  • developer option enabled
  • usb debugging on
  • windows driver is installed.

@stevekenei
Copy link

stevekenei commented Aug 20, 2021

I would like to disable a number of apps on multiple phones, right now I can disable multiple apps on a single phone running a batch script as in the screen shot attached. How can I use this code to run this on multiple apps? ie, can I run this with another .bat? Many thanks!
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment