@echo off
:: 设置adb的文件路径
set "adb_path=E:\SDK\platform-tools"
:: 更新环境变量
set PATH=%adb_path%;%PATH%
:: 白名单包名
set "whitelist=magisk.term com.speedsoftware.rootexplorer org.lsposed.manager com.tencent.mm com.eg.android.AlipayGphone com.cjs.hegui30"
adb devices
set /p device=Please select the device name:
set device=%device%
echo Uninstalling all packages...
:: 获取所有用户安装的应用包名并存储到 packages.txt 文件
adb -s %device% shell pm list packages -3 > packages.txt
setlocal enabledelayedexpansion
:: 读取文件并逐行处理
for /f "tokens=2 delims=:" %%a in (packages.txt) do (
:: 检查包名是否是需要保留的应用
set "package=%%a"
:: 检查是否在白名单中
if "!whitelist!"=="!whitelist:%package%=!" (
echo Uninstalling !package!...
adb -s %device% uninstall !package!
) else (
echo Skipping !package! in whitelist
)
)
endlocal
:: 删除临时文件
del packages.txt
:: 执行命令并将结果存储到变量
for /f "tokens=*" %%a in ('adb -s %device% shell pm clear com.android.launcher3 2^>^&1') do (
set result=%%a
)
:: 判断是否包含 "Failed" 字符
echo %result% | find /i "Failed" >nul
if %errorlevel%==0 (
echo Resetting desktop layout failed!
) else (
echo Desktop layout reset successfully.
)
echo All other packages uninstalled except the specified ones.
pause
标签:set,com,whitelist,echo,adb,卸载,packages,安装包
From: https://www.cnblogs.com/Dmail/p/18419998