Batch file 通过bat文件更改网络适配器DNS

Batch file 通过bat文件更改网络适配器DNS,batch-file,dns,Batch File,Dns,几年前,我编写了一个小的批处理脚本,用于自动更改电脑中每个网络适配器的DNS地址。编写批处理脚本后,我将其转换为exe。 与此同时,我丢失了密码,但现在我又需要它 我已找到exe文件并能够提取cmd输出: @echo on SETLOCAL EnableDelayedExpansion ( SET adapterName=Ethernet adapter Ethernet: REM Removes "Ethernet adapter" from the fro

几年前,我编写了一个小的批处理脚本,用于自动更改电脑中每个网络适配器的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

但我不知道如何使它再次工作。我完全忘记了编写批处理脚本。

如果您想要一个HTA来更改DNS?不。在我的组织中,我们有大约100台独立的PC。手动更改DNS将花费大量时间,我想学习第一课循环变量的命令行使用一个
%
,但在批处理脚本中,您必须将其加倍。因此,您必须在for loop中将
%b
替换为
%b
,并且您必须使用carret:
^ |
来退出for loop命令中的管道,而不是在您循环通过的命令中使用
如果您想要更改DNS的HTA?不。在我的组织中,我们有大约100台独立的PC。手动更改DNS将花费大量时间,我想学习第一课循环变量的命令行使用一个
%
,但在批处理脚本中,您必须将其加倍。因此,您必须在for循环中将
%b
替换为
%b
,并且必须使用carret:
^ |
在for循环命令中转义管道,而不是在循环通过的命令中转义