Batch file 使用批处理控制我的网络适配器

Batch file 使用批处理控制我的网络适配器,batch-file,if-statement,goto,Batch File,If Statement,Goto,我试图编写一个简单的批处理文件,询问我是否要启用或禁用网络适配器,然后将答案传递给netsh。(我喜欢在电视上看Netflix时关掉它,这似乎有助于提高质量) 我写了这样一篇文章: set /p %letter%=[(E)nable or (D)isable:] IF %letter=="e". goto enable IF %letter=="d". goto disable :enable set command=enable netsh interface set interface n

我试图编写一个简单的批处理文件,询问我是否要启用或禁用网络适配器,然后将答案传递给netsh。(我喜欢在电视上看Netflix时关掉它,这似乎有助于提高质量)

我写了这样一篇文章:

set /p %letter%=[(E)nable or (D)isable:]
IF %letter=="e". goto enable
IF %letter=="d". goto disable

:enable
set command=enable
netsh interface set interface name="Local Area Connection" admin=%command%
Pause
exit

:disable
set command=disable
netsh interface set interface name="Local Area Connection" admin=%command%
pause
exit

但是“goto”似乎永远不会被遵循。它总是选择第一个子例程。

也删除set命令中变量周围的%:


==
两侧的字符串必须完全匹配。
/i
开关使比较不区分大小写。如果两者都不匹配,则执行下一行-因此总是转到
启用

这里有一个替代方法:

@echo off
set /p letter=[(E)nable or (D)isable:]
IF /i "%letter"=="d"     ipconfig /release *
IF /i "%letter"=="e"     ipconfig /renew
@echo off
set /p letter=[(E)nable or (D)isable:]
IF /i "%letter"=="d"     ipconfig /release *
IF /i "%letter"=="e"     ipconfig /renew