大多出现这种情况都是由于端口被占用造成的,而国内比如360,金山,腾讯QQ,刷机软件等都会抢用5037端口(抢占市场啊),就会导致无法识别手机,悲催程序员了,360,金山等甚至在你不同意的情况下在后台安装他们的软件,实在可恶。不吐槽了。直接进入主题。开始解决这个问题。
我写了一段bat文件以后处理起来很方便,但是在使用之前必须保证adb命令已经配置在环境变量或者你已经在adb目录下。复制下面代码,放到记事本中,然后保存,保存的后缀为.bat。
rem 在使用之前必须要保证adb命令所在的位置已添加在环境变量中!
@echo off
choice /C OCREV /M "C 关闭adb服务,O 开启adb服务,R 重启adb服务,E 退出,V 查看5037端口情况"
if errorlevel 5 goto view
if errorlevel 4 goto end
if errorlevel 3 goto restart
if errorlevel 2 goto close
if errorlevel 1 goto open
:start
choice /C OCRE /M "C 关闭adb服务,O 开启adb服务,R 重启adb服务,E 退出,V 查看5037端口情况"
if errorlevel 5 goto view
if errorlevel 4 goto end
if errorlevel 3 goto restart
if errorlevel 2 goto close
if errorlevel 1 goto open
:view
netstat -ano | find "5037"
echo 输入需要结束的PID(最后一列)
set /p p=
taskkill /F /PID "%p%"
goto start
:open
adb start-server
goto start
:close
adb kill-server
goto start
:restart
adb kill-server
adb start-server
goto start
:end
echo good bye
上述操作完成,双击即可运行。
为了明显知道到底是谁占用的端口,可以首先运行批处理文件然后输入 V 大小写均可。会出现5037端口被使用的情况。最后一行为pid值,输入后回车,就可以kill掉。
1.打开任务管理器,选择查看
2.选择列
3选择pid
4.这个时候在进程里面就会有pid这一列了。
就说到这里吧,希望大家能帮我在完善一下这个批处理文件。现在的功能只有关闭,开启,重启,和查看端口占用。我目前感觉就够用了。大家有问题一起探讨。