标题: [文件管理] adb 常用命令集合 [打印本页]
作者: went 时间: 2020-11-29 16:00 标题: adb 常用命令集合
本帖最后由 went 于 2020-11-29 19:14 编辑
adb工具包下载:
1.http://bcn.bathome.net/s/tool/index.html?key=adb
2.adb+aapt
adb 基础命令请参考
https://www.cnblogs.com/laoluoits/p/10985442.html
常用命令:
检测设备:复制代码
有线连接设备:复制代码
无线连接设备:- REM 命令: adb connect 手机IP:5555
- REM 手机电脑连接到同一局域网,手机打开网络ADB调试
- REM 出现connect to IP 即成功
- adb connect 10.2.1.172:5555
复制代码
推送文件到手机- REM 命令:adb push "电脑文件路径" "手机文件路径"
- REM 保存原文件名
- adb push "G:\Desktop\1.txt" "/sdcard/"
- REM 保存新文件名
- adb push "G:\Desktop\1.txt" "/sdcard/2.txt"
复制代码
上传手机文件到电脑- REM 命令:adb pull "手机文件路径" "电脑文件路径"
- REM 保存原文件名
- adb pull "/sdcard/1.txt" "G:\Desktop"
- REM 保存新文件名
- adb pull "/sdcard/1.txt" "G:\Desktop\A.txt"
复制代码
以下是自用代码分享
作者: went 时间: 2020-11-29 16:02
1.手机相册备份,DCIM文件夹,备份jpg和mp4文件- @echo off
- REM adb工具包文件夹
- set "adbPath=G:\Phone\tool"
- REM 照片保存文件夹
- set "imgPath=G:\DCIM"
- REM 视频保存文件夹
- set "mp4Path=G:\video"
- set "path=%path%;%adbPath%"
- REM 检测设备
- adb devices | findstr /e /i "device" >nul 2>nul || ( adb devices & echo No Devices! & pause&exit )
- mkdir "%imgPath%" "%mp4Path%" >nul 2>nul
- REM 备份照片
- for /f "delims=" %%i in ('adb shell find /sdcard/dcim -name "*.jpg"') do (
- set /p "=pull %%i "<nul
- if not exist "%imgPath%\%%~nxi" (
- adb pull "%%i" "%imgPath%\%%~nxi" >nul 2>nul
- echo done!
- ) else echo skip
- )
- REM 备份视频
- for /f "delims=" %%i in ('adb shell find /sdcard/dcim -name "*.mp4"') do (
- set /p "=pull %%i "<nul
- if not exist "%mp4Path%\%%~nxi" (
- adb pull "%%i" "%mp4Path%\%%~nxi" >nul 2>nul
- echo done!
- ) else echo skip
- )
- pause&exit
复制代码
作者: went 时间: 2020-11-29 17:41
本帖最后由 went 于 2020-11-29 19:25 编辑
2.应用一键备份,多开即可实现多线程备份(65001代码页,脚本不能有中文)
adbPath = ADB工具包文件夹(adb+aapt)
backupPath = apk备份文件夹- @echo off & chcp 65001 & cls & cd /d "%~dp0"
- setlocal enabledelayedexpansion
- REM adb tool path
- set "adbPath=G:\Desktop\adb"
- REM backup path
- set "backupPath=G:\Desktop\apk"
- mkdir "%backupPath%" >nul 2>nul
- set "path=%path%;%adbPath%"
- REM counter
- set "count=0"
- for /f "tokens=1* delims=:" %%i in ('adb shell pm list package -3') do (
- set /a "count+=1"
- echo !count!:%%j
- set "versionCode=" & set "versionName=" & set "remotePath=" & set "chsName="
- REM get versionCode,versionName
- for /f "tokens=1,2 delims== " %%a in ('adb shell pm dump "%%j" ^| findstr /i "versionCode= versionName="') do (
- if /i "%%a"=="versionCode" set "versionCode=%%b"
- if /i "%%a"=="versionName" set "versionName=%%b"
- )
- set "localName=[%%j]-!versionCode!-V!versionName!.apk"
- REM get remotePath
- for /f "tokens=2 delims=:" %%a in ('adb shell pm path "%%j"') do set "remotePath=%%a"
- echo pulling ...
- REM pull apk
- if exist "%backupPath%\*!localName!" (
- REM if exist ,skip backup
- for %%a in ("%backupPath%\*!localName!") do echo skip %%a
- ) else (
- adb pull "!remotePath!" "%backupPath%\!localName!" >nul
- REM get chinese name
- for /f "tokens=2 delims=:'" %%a in ('aapt dump badging "%backupPath%\!localName!" ^| findstr /i "application-label:"') do set "chsName=%%a"
- REM rename
- if not "!chsName!"=="" move /y "%backupPath%\!localName!" "%backupPath%\!chsName!!localName!" >nul
- echo done. %backupPath%\!chsName!!localName!
- )
- echo --------------------------------------------------
- )
- echo backup done.
- pause&exit
复制代码
作者: went 时间: 2020-11-29 18:23
本帖最后由 went 于 2020-11-29 18:28 编辑
3.应用一键还原,全程静默安装,无须Root权限(65001代码页,脚本不能有中文)
adbPath = ADB工具包文件夹
backupPath = apk安装包文件夹
savePath = 手机保存apk的文件夹- @echo off & chcp 65001 & cls & cd /d "%~dp0"
- setlocal enabledelayedexpansion
- REM adb tool path
- set "adbPath=G:\Desktop\adb"
- REM backup path
- set "backupPath=G:\Desktop\apk"
- REM save path
- set "savePath=/sdcard/apk"
- mkdir "%backupPath%" >nul 2>nul
- set "path=%path%;%adbPath%"
- REM counter
- set "count=0"
- for %%i in ("%backupPath%\*.apk") do (
- set /a "count+=1"
- echo !count!:%%~nxi
- REM check exist
- adb shell if [ -f '%savePath%/%%~nxi' ];then echo true;else echo false;fi | findstr /i "true" >nul 2>nul && (
- REM exist
- echo skip push
- ) || (
- REM not exist
- REM push to %savePath%
- echo pushing...
- adb push "%%i" "%savePath%/%%~nxi" >nul 2>nul
- echo push done.
- )
- REM copy apk to /data/local/tmp
- adb shell cp '%savePath%/%%~nxi' 'data/local/tmp'
- REM install apk
- echo install ...
- adb shell pm install 'data/local/tmp/%%~nxi'
- REM del temp apk
- adb shell rm -rR 'data/local/tmp/%%~nxi'
- echo ----------------------------------------------------
- )
- pause&exit
复制代码
作者: went 时间: 2020-11-30 20:41
4.解决手机无法弹出USB授权对话框- @echo off
- REM 一键导入adb_keys
- adb devices | findstr /i /e "device" >nul 2>nul && (
- echo.
- echo. adb 连接正常 退出...
- echo.
- pause&exit
- )
- adb devices | findstr /i /e "unauthorized" >nul 2>nul && (
- echo.
- echo. adb 授权未成功,请手动进入recovery模式再次运行本程序
- echo.
- pause&exit
- )
- adb devices | findstr /i /e "recovery" >nul 2>nul && (
- echo.
- echo. recovery模式.
- echo.
- call :checkAdbKey
- echo. 开始推送公钥文件
- echo.
- adb shell mkdir "/data/misc/adb/" >nul 2>nul
- adb push "%USERPROFILE%\.android\adbkey.pub" "/data/misc/adb/adb_keys"
- echo.
- echo. 推送完成,按任意键重启手机.
- pause>nul
- adb reboot
- echo. 重启完成,按任意键退出.
- pause>nul
- exit
- )
- echo.
- echo. 没有设备连接
- echo.
- pause&exit
-
- :checkAdbKey
- if not exist "%USERPROFILE%\.android\adbkey.pub" (
- echo. 未找到 adbkey.pub 公钥文件
- echo.
- echo. 要生成adbkey.pub,请按任意键重启adb服务
- pause >nul
- echo.
- echo. 请稍后...
- echo.
- taskkill /im adb.exe /f >nul 2>nul
- adb start-server
- call :checkAdbKey
- ) else (
- echo.
- echo. 公钥文件:%USERPROFILE%\.android\adbkey.pub
- echo.
- goto :eof
- )
复制代码
作者: went 时间: 2022-10-18 21:04
5.备份应用数据 需要root权限- @echo off & cd /d "%~dp0"
- REM 检查root权限
- adb shell su -c 'ls' 2>nul | findstr /be system >nul 2>nul || ( echo 无root权限 & pause&exit)
- REM 指定数据包保存文件夹和包名
- set "data_dir=data"
- set "pkg_name=com.tencent.mm"
-
- REM 命令设置
- set "adb_shell=adb shell"
- set "adb_shell_su=adb shell su -c"
-
- REM 路径设置
- mkdir "%data_dir%" 2>nul
- set "data1=sdcard/Android/data/%pkg_name%/"
- set "data2=data/data/%pkg_name%/"
- set "data_gz=/sdcard/%pkg_name%.gz"
- set "save_gz=data\%pkg_name%.gz"
-
- echo. 开始备份 %pkg_name%
-
- echo. 打包数据...
- %adb_shell_su% tar -czf "%data_gz%" "%data1%" "%data2%"
-
- echo. 备份数据...
- adb pull "%data_gz%" "%save_gz%"
-
- echo. 删除数据包...
- %adb_shell% rm -rR "%data_gz%"
-
- echo. 备份完成
-
- pause&exit
复制代码
作者: went 时间: 2022-10-18 21:05
6.恢复应用数据 需要root权限- @echo off & cd /d "%~dp0"
- REM 检查root权限
- adb shell su -c 'ls' 2>nul | findstr /be system >nul 2>nul || ( echo 无root权限 & pause&exit)
- REM 指定数据包保存文件夹和包名
- set "data_dir=data"
- set "pkg_name=com.tencent.mm"
-
- REM 命令设置
- set "adb_shell=adb shell"
- set "adb_shell_su=adb shell su -c"
-
- REM 路径设置
- mkdir "%data_dir%" 2>nul
- set "data_gz=/sdcard/%pkg_name%.gz"
- set "save_gz=data\%pkg_name%.gz"
-
- echo. 推送数据包...
- if not exist "%save_gz%" (echo. 不存在%pkg_name%的备份 & pause&exit)
- adb push "%save_gz%" "%data_gz%"
-
- echo. 释放数据包
- %adb_shell% am force-stop %pkg_name%
- %adb_shell_su% tar -xzf "%data_gz%"
-
- echo. 设置权限
- for /f "tokens=3" %%i in ('%adb_shell% ls -l '/sdcard/Android/data' ^| findstr /e /C:" %pkg_name%"') do (
- echo. %%i
- %adb_shell_su% chown -hR %%i:%%i "/data/data/%pkg_name%"
- )
-
- echo. 删除数据包
- %adb_shell% rm -rR "%data_gz%"
-
- echo. 恢复成功
-
- pause&exit
复制代码
作者: lancer 时间: 2022-10-29 20:48
adb push和adb pull不支持中文路径和中文名,这个要说明一下。
楼主能找到修改版的adb么,支持中文路径的那种。
作者: 77七 时间: 2024-3-28 14:21
本帖最后由 77七 于 2024-3-28 14:31 编辑
因为安卓手机应用读取剪贴板,可能导致隐私泄露;应用内震动无法从应用内或者系统设置中关闭,特搜集了相关adb命令代码(代码比较基础,就不贴出处了),写成批处理自用,在此借楼分享一下给需要的朋友
本代码只写了 剪贴板、震动,可以自己尝试输入其它项目。因本人水平十分有限,疏忽、错误难免,代码仅供参考。
- @echo off
- rem 批处理保存为ansi编码格式
- :1
- adb devices |findstr /rec:"device" 1>nul
- if errorlevel 1 (
- echo 请确保手机已经打开[允许USB调试] 并连接到电脑,按【回车键】再次尝试
- pause
- goto :1
- ) else (
- echo 连接成功!
- )
- echo=
- echo 说明:
- echo 1.项目举例,剪贴板【READ_CLIPBOARD】震动【VIBRATE】
- echo 2.允许【allow】禁止【ignore】
- echo 3.均区分大小写
- echo=
- setlocal
- set /p c1=输入项目,如需要管理剪贴板权限,则输入READ_CLIPBOARD:
- set /p c2=输入操作,如需要禁止权限,则输入ignore:
-
- if "%c2%" equ "allow" (
- set c3=ignore
- ) else (
- set c3=allow
- )
-
- setlocal enabledelayedexpansion
- call :2 "%c1%" "%c2%" "%c3%"
- endlocal
- endlocal
- goto :1
-
- :2
- echo=
- echo 当前 "%~3" 权限app
- echo=
- for /f "delims=" %%a in ('adb shell cmd appops query-op --user 0 %~1 %~3') do (
- set /a n+=1001
- echo [!n:~-3!] %%a
- set #!n:~-3!=%%a
- )
- if not defined n (
- echo 无符合条件的app
- exit /b
- )
- echo=
- set /p c4=输入所有需要 "%~2" 的序号,以空格分隔:
- echo=
- for %%a in (%c4%) do (
- adb shell cmd appops set !#%%a! %~1 %~2
- rem 此命令成功失败无提示,请自行查看效果
- echo %~2 !#%%a! %~1 权限
- )
- echo=
- echo 操作完成
- echo=
- echo=
- exit /b
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |