本地连接状态:批处理文件



我正在尝试编写批处理脚本,以确定是否插入了"本地连接"适配器。

    set nicValue=
for /f "delims=" %%a in ('netsh interface show interface "Local Area Connection"') do @set nicValue=%%a
echo %nicValue%
if "%nicValue%"=="Connect state:        Connected" echo On

我能够获得正确的输出并将其保存到一个名为%nicValue%的变量中,但是,我无法基于该输出运行'if'命令。截至目前,如果批处理文件可以看到"连接状态"one_answers"已连接",我所要做的就是回显"On",但我不知所措。任何帮助将非常感激!

为什么不直接在echo on循环中过滤:并获得一个干净的值。像这样:

    set nicValue=
for /f "tokens=3 delims=: " %%a in ('netsh interface show interface "Local Area Connection"') do @set nicValue=%%a
echo %nicValue%
if "%nicValue%"=="Connected" echo Connected

但我认为你的问题是使用echo语句,当你把on变成echo Connected状态时,你需要把它重新表述为其他东西,比如CC_8

最新更新