Windows Batch / ADB - 检查多个设备的已安装应用程序

时间:2017-03-16 15:58:25

标签: android windows batch-file adb

我正在使用FOR命令和AAPT命令从目录中的多个APK获取包名称。我使用单独的FOR命令和ADB命令列出设备中所有第三方安装的应用程序。

我已经能够交叉引用这些来获得我想要的单个设备的输出。当我收到错误时,我不确定如何重新安排脚本来管理多个设备。

我希望你能理解我想要实现的目标。请参阅下面的尝试:

::Global
@echo off

set AAPT=tools\aapt.exe
set GREP=tools\grep.exe
set CUT=tools\cut.exe

:: Applications
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F "tokens=1,2 skip=1" %%N IN ('adb devices') DO (
    SET IS_DEV=%%O
    if "!IS_DEV!" == "device" (
        SET SERIAL=%%N
        for /f "delims=" %%P in ('dir /b ^"APKs\*.apk^"') do (
            SET APK=%%P
            for /f "tokens=1 delims=" %%Q in ('%AAPT% d badging APKs\!APK! ^| !GREP! "package: name=" ^| !CUT! -d' -f2') do (
                set package=%%Q
                if "!package!" == "" set package=Unknown (
                echo !package!>>"%userprofile%\desktop\PCAPPS.txt"
                )
            )
        )
    )
)
FOR /F "tokens=1,2 skip=1" %%R IN ('adb devices') DO (
    if "!IS_DEV!" == "device" (
        FOR /F "tokens=1 delims=" %%U IN ('adb shell "pm list packages -3" ^| !CUT! -f 2 -d ":"^') DO (
        SET DEVPACKAGE=%%U
        echo !DEVPACKAGE!>>"%userprofile%\desktop\DEVAPPS.txt"
                )
            )
        )
    )
)
FOR /f "tokens=*" %%a in ('FINDSTR /vlxg:"%userprofile%\desktop\DEVAPPS.txt" "%userprofile%\desktop\PCAPPS.txt"') DO (
    set NOTDEVAPP=%%a
    echo !SERIAL! does not have package !NOTDEVAPP! installed
    )
del "%userprofile%\desktop\DEVAPPS.txt"
del "%userprofile%\desktop\PCAPPS.txt"
)
ENDLOCAL
@pause

这与问题有关:Windows Batch / ADB - Check if installed .apk matches .apk from a directory

1 个答案:

答案 0 :(得分:0)

逻辑错误。嵌套功能正常工作。

watcher.IncludeSubdirectories = true;