几年前,我写了一个小批量脚本来自动更改PC中存在的每个网络适配器的DNS地址。在我编写批处理脚本后,我将其转换为exe。 与此同时,我丢失了代码,但现在又需要它了。
我找到了exe文件,并且能够提取cmd输出:
@echo on
SETLOCAL EnableDelayedExpansion
(
SET adapterName=Ethernet adapter Ethernet:
REM Removes "Ethernet adapter" from the front of the adapter name
SET adapterName=!adapterName:~17!
REM Removes the colon from the end of the adapter name
SET adapterName=!adapterName:~0,-1!
netsh interface ipv4 set dns name="!adapterName!" static 8.8.8.8 primary
netsh interface ipv4 add dns name="!adapterName!" 8.8.4.4 index=2
netsh interface ipv6 add dnsserver "!adapterName!" 2001:4860:4860::8888
)
FOR /F "tokens=* delims=:" %b IN ('IPCONFIG | FIND /I "WIRELESS LAN ADAPTER"') DO (
SET WadapterName=%b
REM Removes "Ethernet adapter" from the front of the adapter name
SET WadapterName=!WadapterName:~21!
REM Removes the colon from the end of the adapter name
SET WadapterName=!WadapterName:~0,-1!
netsh interface ipv4 set dns name="!WadapterName!" static 8.8.8.8 primary
netsh interface ipv4 add dns name="!WadapterName!" 8.8.4.4 index=2
netsh interface ipv6 add dnsserver "!WadapterName!" 2001:4860:4860::8888
)
ipconfig /flushdns
但我不知道如何让它再次运作。我完全忘记编写批处理脚本。