BAT脚本自动安装apk

首先创建一个安装apk的dos脚本如下:

@echo off
set errorMsg=""
set ip=%1%
set fileName=%2%
set auto=%3%
cd adb
adb.exe kill-server
if "%ip%"=="" set /p ip=input ip address:
if "%ip%"=="" (echo will connect by usb) else (adb.exe connect %ip%)
if "%fileName%"=="" set /p fileName=FileName(Example: myName.apk):

echo %fileName% is pushing... 
adb.exe push ../apk/%fileName% /sdcard/%fileName%
if errorlevel 0 (echo push apk completed) else (set errorMsg=push apk failed & goto :error)
adb.exe shell pm install -r /sdcard/%fileName%
if errorlevel 0 (echo install completed) else (set errorMsg=install failed & goto :error)

echo completed
goto :exit

:error
echo completed with error: %errorMsg%

:exit
if "%auto%"=="" (pause>nul) else (exit)

windows下双击运行,输入设备IP(默认不输入会使用USB连接),再输入APK包的绝对路径,回车后自动安装:


image.png

添加批量安装功能:

@echo off
set ipDir=./batch/ip
echo !***************************!
echo !*** 1.installer1.bat ***!
echo !*** 2.installer2.bat ***!
echo !***************************!
choice /c 12 /m "Choice installer "
if errorlevel 2 set bat=installer2.bat
if errorlevel 1 set bat=installer1.bat
set /p fileName=FileName(Example: myName.apk):
cd ../
echo Failed ip list > %ipDir%/failed.txt
for /f "delims=" %%i in (%ipDir%/ips.txt) do (
start /wait %bat% %%i %fileName% autoExit
if errorlevel 0 (echo %%i install success) else (echo %%i install failed & echo %%i >> %ipDir%/failed.txt)
)
echo completed
pause>nul

批量脚本会根据ips.txt文件,逐行连接IP,自动升级apk文件,假如IP地址连接失败,会在目录下生成一个failed.txt文件,可以根据文件内容,检查与这些IP的网络连接,然后再进行二次处理。

操作步骤:

1.在ip文件夹下,把收集到的ip地址保存到ips.txt文件中(每行一个IP)
2.执行batch.bat文件
3.按提示选择执行的脚本,直接键盘输入1或2
4.输入升级的apk文件名,和普通单个升级一样
5.等待执行完毕

你可能感兴趣的:(BAT脚本自动安装apk)