Sujet : Re: Do you use ADB (or ScreenCopy) with Android & Windows?
De : marion (at) *nospam* facts.com (Marion)
Groupes : comp.mobile.androidDate : 09. May 2025, 11:21:08
Autres entêtes
Organisation : BWH Usenet Archive (https://usenet.blueworldhosting.com)
Message-ID : <vvkkuk$ni4$1@nnrp.usenet.blueworldhosting.com>
References : 1 2 3 4 5 6 7
User-Agent : MacSOUP/2.8.5 (ea919cf118) (Mac OS 10.12.6)
On Fri, 9 May 2025 11:12:54 +0100, Andy Burns wrote :
If it's above 1023, you should reserve the port using:
C:\> netsh int ipv4 add excludedportrange protocol=tcp startport=55555 numberofports=1
And presumably you could check the exitcode of the netsh command, and if
it fail increment the port number and retry, finally setting the
environment variable to the actual port number?
y'mean some4thing like this?
@echo off
setlocal
set "targetPort=55555"
set "maxRetries=10"
set "retryCount=0"
:reservePort
echo Trying to reserve port %targetPort%...
netsh int ipv4 add excludedportrange protocol=tcp startport=%targetPort% numberofports=1
if errorlevel 1 (
echo Failed to reserve port %targetPort%. Error code: %errorlevel%
set /a retryCount+=1
if %retryCount% lss %maxRetries% (
set /a targetPort+=1
echo Retrying with port %targetPort%...
goto :reservePort
) else (
echo Failed to reserve a port after %maxRetries% retries. Exiting.
goto :end
)
) else (
echo Successfully reserved port %targetPort%.
echo Setting ANDROID_ADB_SERVER_PORT environment variable to %targetPort%
setx ANDROID_ADB_SERVER_PORT %targetPort% /M
echo Please note that system environment variables changes may require a reboot to fully take effect for all processes.
goto :end
)
:end
endlocal
pause