@echo off
setlocal enabledelayedexpansion
title APKs ADB Install Tool v1.0.0
color 2f
set adb="%~dp0\adb.exe"
set fastboot="%~dp0\fastboot.exe"
set /a c_num=1
set /a File_Num=0
set /a S_Num=0
set /a F_Num=0
echo ===============================================================================
echo 本脚本会自动安装目录下所有APK文件(包括子文件夹)到ANDROID设备
echo ===============================================================================
:CHECK
echo.
echo 正在检测手机连接情况......
%adb% shell echo > nul 2>&1
IF not ERRORLEVEL 0 goto NODEV
echo 设备已连接,请稍候......
echo.
goto FILE_CHECK
:NODEV
echo 未连接手机,如果已插入手机,请打开USB调试,安装好驱动......
echo 请按任意键继续......
pause >nul
goto Check
:FILE_CHECK
echo.
echo 正在扫描APK文件,请稍后......
if exist tmp.apk del tmp.apk
if exist fail.log del fail.log
if exist %temp%\apk_tmp.txt del %temp%\apk_tmp.txt
for /f "delims=: tokens=1" %%i in ('dir /a/b/s *.apk 2^>nul^| findstr /n .*') do set "File_Num=%%i"
if !File_Num!==0 goto NO_APK
echo 找到%File_Num%个APK文件,准备安装......
goto SET_PRAM
:NO_APK
echo.
echo 找不到APK文件,请确认APK已经放入当前目录......
echo 请按任意键继续......
pause >nul
goto FILE_CHECK
:SET_PRAM
set o=
set /p o=是否启用覆盖安装模式? (Y/N,默认N):
echo.
if /i "%o%"=="Y" goto YES
goto NO
:YES
echo 启用
echo.
set pram=-r
goto INSTALL
:NO
echo 不启用
echo.
goto INSTALL
:INSTALL
echo 开始安装Android应用程序 ......
for /f "delims=" %%a in ('dir /a-d/s/b *.apk') do (
echo.
echo 正在安装第!c_num!个,共%File_Num%个
copy "%%a" tmp.apk > nul
echo 文件信息: %%a
%adb% install %pram% tmp.apk >> %temp%\apk_tmp.txt
set /a c_num+=1
for /f "delims=" %%i in (%temp%\apk_tmp.txt) do (
echo %%i | findstr "Success" && set /a mk=1 || set /a mk=0 >nul
set "var=%%i"
)
if !mk!==1 (set /a S_Num+=1) else (echo !var!&&set /a F_Num+=1 &&echo !var!>>fail.log&&echo %%a>>fail.log&&echo ...>>fail.log)
del %temp%\apk_tmp.txt
del tmp.apk
echo -------------------------------------------------------------------------------
)
echo.
echo 已安装%num%个APK应用程序,成功%S_Num%个,失败%F_Num%个&&echo.
if %F_Num%==0 goto DEL_CHOOSE else goto Show_FAIL_LIST
:Show_FAIL_LIST
echo 安装失败的文件:
for /f "delims=," %%i in (fail.log) do (
echo %%i
)
echo.
echo 按任意键退出并查看安装失败文件列表
pause>nul
echo 安装失败文件列表 >> fail.log
start notepad "%~dp0\fail.log"&&goto END >nul
goto END
:DEL_CHOOSE
set o=
set /p o=是否删除APK文件? (Y/N,默认退出):
if /i "%o%"=="Y" goto DEL_APK
goto END
:DEL_APK
echo.
del /s *.apk
echo.
echo 所有文件已删除,按任意键退出
pause>nul
:END
exit