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.等待执行完毕

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容