@echo off chcp 65001 >nul setlocal enabledelayedexpansion echo ======================================== echo Enable ADB TCP/IP Mode (Port 5555) echo ======================================== echo. REM Get the directory where this batch file is located set "SCRIPT_DIR=%~dp0" set "PROJECT_ROOT=%SCRIPT_DIR%.." REM Use ADB from project root adb-tools directory set "ADB_PATH=%PROJECT_ROOT%\adb-tools\adb.exe" REM Check if local ADB exists, otherwise fallback to system PATH if not exist "%ADB_PATH%" ( echo Warning: Local ADB not found at %ADB_PATH% echo Falling back to system PATH... set "ADB_PATH=adb" ) echo [0/3] Using ADB: %ADB_PATH% echo. REM Check if port 5037 is in use and kill the process if needed echo [1/3] Checking ADB daemon port (5037)... set "PORT_FOUND=0" set "KILLED_PID=" for /f "tokens=5" %%a in ('netstat -ano 2^>nul ^| findstr :5037') do ( if !PORT_FOUND! equ 0 ( set "PID=%%a" if not "!PID!"=="" ( set "PORT_FOUND=1" set "KILLED_PID=!PID!" echo Port 5037 is in use by process ID: !PID! echo Attempting to kill process... taskkill /F /PID !PID! 2>nul if !errorlevel! neq 0 ( echo Warning: Failed to kill process !PID!, may need administrator privileges. ) else ( echo Process !PID! killed successfully. ) goto :port_killed ) ) ) :port_killed REM Kill all ADB processes regardless of port check echo Killing all ADB processes... taskkill /F /IM adb.exe 2>nul if !errorlevel! neq 0 ( echo Warning: Failed to kill ADB processes, may need administrator privileges. echo Please run this script as Administrator. ) else ( echo All ADB processes terminated. ) REM Wait a bit for processes to fully terminate if !PORT_FOUND! equ 1 ( timeout /t 2 /nobreak >nul ) else ( timeout /t 1 /nobreak >nul ) echo. echo [2/3] List connected devices... "%ADB_PATH%" devices echo. echo [3/3] Enable TCP/IP mode... "%ADB_PATH%" tcpip 5555 echo. echo ======================================== echo Done echo ======================================== echo. pause