【问题标题】:@choice in .bat script is running all commands when choosing commands in same file在同一文件中选择命令时,.bat 脚本中的 @choice 正在运行所有命令
【发布时间】:2022-10-08 23:37:31
【问题描述】:

我对这个 bat 文件的问题是我试图让最终用户选择使用 .bat 脚本阻止成人和赌博网站,我面临的问题是所有命令都一起运行,无论选择如何

有没有办法将它们分开,是否有更好的方法可以利用 C++ 程序来做到这一点?

Project Link AGShield

 #!/bin/bash 
@ECHO OFF
CLS 
TITLE = Block Adult and Gambling Windows by andgoedu

ECHO 1. Changing_hosts_file
ECHO 2. ChangingDNS_CloudFlare_Family_Win10
ECHO 3. ChangingDNS_CloudFlare_Family_Shield_Win_7
ECHO 4. Check_DNS_Servers 



CHOICE /C 1234 /M "Enter your choice:"



:: Note - list ERRRORLEVELS in decreasing order
IF ERRORLEVEL 4 GOTO Check_DNS_Servers 
IF ERRORLEVEL 3 GOTO CloudFlareDNS_Family_Shield_Win_7
IF ERRORLEVEL 2 GOTO DNS_CloudFlare_Family_Win10
IF ERRORLEVEL 1 GOTO hostsfile

GOTO START
:hostsfile
    ECHO "Copying the original Windows Hosts file "
    PAUSE
    CD C:\Users\Public\Documents
    MKDIR OriginalFile
    CD
    CD C:\Windows\System32\drivers\etc
    XCOPY hosts C:\Users\Public\Documents\OriginalFile
    ECHO "Your original hosts was copied To C:\Users\Public\Documents\OriginalFile" 
    PAUSE
    ECHO "Deleting Old hosts file .............................................................." 
    DEL C:\Windows\System32\drivers\etc\hosts 
    ECHO "Deleting Old hosts file .............................................................." 
    XCOPY "%~dp0\hosts" "C:\Windows\System32\drivers\etc" /w 
    ECHO "Your Hosts File Was Changed SuccessFully" 
    PAUSE
    CLS
;
GOTO END

GOTO START

:DNS_CloudFlare_Family_Win10
    ECHO "Changing Search Engine Results to Safe Family (CloudFlare Family DNS)."
    ECHO  " Changing DNS Of This PC-Only Wifi..............................................................................." 
    netsh interface ipv4 set dns "Wi-Fi" static 185.228.168.168 primary
    netsh interface ipv4 add dns "Wi-Fi" 185.228.169.168 index=2
    netsh interface ipv6 set dns "Wi-Fi" static 2a0d:2a00:1:: primary
    netsh interface ipv6 add dns "Wi-Fi" 2a0d:2a00:2:: index=2
    ECHO  " Changing DNS Of This PC-Only Ethernet ..............................................................."
    netsh interface ipv4 set dns "Ethernet" static 185.228.168.168 primary
    netsh interface ipv4 add dns "Ethernet" 185.228.169.168 index=2
    netsh interface ipv6 set dns "Ethernet" static 2a0d:2a00:1:: primary
    netsh interface ipv6 add dns "Ethernet" 2a0d:2a00:2:: index=2
    netsh interface ipv4 set dns "Local Area Connection" static 185.228.168.168 primary
    netsh interface ipv4 add dns "Local Area Connection" 185.228.169.168 index=2
    netsh interface ipv6 set dns "Local Area Connection" static 2a0d:2a00:1:: primary
    netsh interface ipv6 add dns "Local Area Connection" 2a0d:2a00:2:: index=2

    ECHO " Changing DNS Of This PC-Only Local Area Connection.............................................."
    ipconfig /flushdns
    ipconfig /release 
    ipconfig /renew 
    ECHO "Restarted Network Adapters" 
    PAUSE
    PROMPT
    CLS
;
GOTO END

GOTO START
:CloudFlareDNS_Family_Shield_Win_7
   ECHO "Windows 7 Ethernet"
   netsh interface ip set dns "Wi-Fi" static 1.1.1.3  primary
   netsh interface ip add dns "Ethernet" static 1.0.0.3 index=2
   netsh interface ipv6 set dns "Wi-Fi" static 2a0d:2a00:1:: primary
   netsh interface ipv6 add  dns "Wi-Fi" 2606:4700:4700::1003 index=2        
   ECHO "Win7 Wifi"
   netsh interface ip set dns "Wi-Fi" static 1.1.1.3 primary
   netsh interface ip add  dns "Wi-Fi" static 1.0.0.3 index=2
   netsh interface ipv6 set dns "Wi-Fi" static 2a0d:2a00:1:: primary
   netsh interface ipv6 add  dns "Wi-Fi" 2606:4700:4700::1003 index=2
   ipconfig /flushdns
   ipconfig /release 
   ipconfig /renew 
   ECHO "Restarted Network Adapters" 
   ECHO "Check DNS Servers ?"
   PAUSE
;
GOTO END

:Check_DNS_Servers 
    IPCONFIG /ALL
    ECHO "CHECKOUT THE NEW DNS SERVERS DNS Servers" 
   PAUSE

;
GOTO END


【问题讨论】:

  • Bash 和批处理是完全不相关的语言。除了 Shebang,您还编写了一个批处理脚本。此外,标签只是路标,而不是障碍,所以没有什么可以告诉脚本不是继续前进。此外,标签不能包含空格,因此您创建了三个名为 :Changing 的标签。
  • 谢谢你我会改变命名我可以问你我将如何通过基本上正确地调用它来阻止它,因为我有命名错误我是正确的吗?
  • 只有goto 中的第一个字符串是有效的,所以所有changing.... 标签都是相同的。批处理dimply逐行执行,直到达到gotocallexit或物理文件结尾,所以它会简单地从:Changing (hosts file) 运行到文件结尾,因为有在每个“部分”的末尾没有goto start。而且...标签start 似乎不存在。
  • 在为每个选项添加正确的命名和正确的开始和结束后现在可以使用

标签: batch-file cmd dns


【解决方案1】:

@Magoo & @SomethingDark 用他们的 cmets 帮我解决了这个问题

#!/bin/bash 
@ECHO OFF
CLS 
TITLE = Block Adult and Gambling Windows by andgoedu

ECHO 1. Changing_hosts_file
ECHO 2. CleanBrowsing_Family_Win10
ECHO 3. Family_Shield_CleanBrowsing_Win_7
ECHO 4. DNS_CloudFlare_Family_Win10
ECHO 5. CloudFlareDNS_Family_Shield_Win_7
ECHO 6. GoogleDNS_Win7
ECHO 7. GoogleDNS_Win10
ECHO 8. Check_DNS_Servers 



CHOICE /C 12345678 /M "Enter your choice:"



:: Note - list ERRRORLEVELS in decreasing order

IF ERRORLEVEL 8 GOTO Check_DNS_Servers 
IF ERRORLEVEL 7 GOTO GoogleDNS_Win10
IF ERRORLEVEL 6 GOTO GoogleDNS_Win7
IF ERRORLEVEL 5 GOTO DNS_CloudFlare_Family_Win10
IF ERRORLEVEL 4 GOTO DNS_CloudFlare_Family_Win10
IF ERRORLEVEL 3 GOTO Family_Shield_CleanBrowsing_Win_7
IF ERRORLEVEL 2 GOTO CleanBrowsing_Family_Win10
IF ERRORLEVEL 1 GOTO hostsfile

GOTO START
:hostsfile
    ECHO "Copying the original Windows Hosts file "
    PAUSE
    CD C:UsersPublicDocuments
    MKDIR OriginalFile
    CD
    CD C:WindowsSystem32driversetc
    %SystemRoot%System32opy.exe hosts C:UsersPublicDocumentsOriginalFile
    ECHO "Your original hosts was copied To C:UsersPublicDocumentsOriginalFile" 
    PAUSE
    ECHO "Deleting Old hosts file .............................................................." 
    DEL C:WindowsSystem32driversetchosts 
    ECHO "Deleting Old hosts file .............................................................." 
    %SystemRoot%System32opy.exe "%~dp0hosts" "C:WindowsSystem32driversetc" /w 
    ECHO "Your Hosts File Was Changed SuccessFully" 
    PAUSE
    CLS
REM This Script Just Changes the hosts file to the family safe host file
GOTO END

GOTO START
:CleanBrowsing_Family_Win10
    ECHO "Changing Search Engine Results to Safe Family CleanBrowsing"
    ECHO  ".............Changing IPV4 DNS Of This PC-Only Wifi CleanBrowsing ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Wi-Fi" static  185.228.168.168 primary 
    %SystemRoot%System32
etsh.exe interface ipv4 add dnsservers "Wi-Fi" 185.228.169.168 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Wifi CleanBrowsing ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Wi-Fi" static 2a0d:2a00:1:: primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Wi-Fi" 2a0d:2a00:2:: index=2 
    ECHO  ".............Changing IPV4 DNS Of This PC-Only Ethernet CleanBrowsing ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Ethernet" static  185.228.168.168 primary 
    %SystemRoot%System32
etsh.exe interface ipv4 add dnsservers "Ethernet" 185.228.169.168 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Ethernet CleanBrowsing ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Wi-Fi" static  2a0d:2a00:1:: primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Wi-Fi" 2a0d:2a00:2:: index=2 
    ECHO  ".............Changing IPV4 DNS Of This PC-Only Local Area Connection CleanBrowsing ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Local Area Connection" static  185.228.168.168 primary  
    %SystemRoot%System32
etsh.exe  interface ipv4 add dnsservers "Local Area Connection" 185.228.169.168 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Local Area Connection CleanBrowsing ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Local Area Connection" static 2a0d:2a00:1:: primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Local Area Connection" 2a0d:2a00:2:: index=2 
    %SystemRoot%System32ipconfig.exe /flushdns
    ECHO "...................Flushing DNS..............." 
    %SystemRoot%System32ipconfig.exe /release 
    ECHO "....................Releasing DNS................." 
    %SystemRoot%System32ipconfig.exe /renew 
    ECHO ".......................Renewing DNS............." 
    %SystemRoot%System32ipconfig.exe /all
    ECHO "Restarted Network Adapters and CHECK DNS Servers" 
    PAUSE
    PROMPT
    CLS    

GOTO END

GOTO START
:Family_Shield_CleanBrowsing_Win_7
    ECHO "Windows 7 Ethernet"
    %SystemRoot%System32
etsh.exe interface ip set dns "Ethernet" static 185.228.168.168 primary
    %SystemRoot%System32
etsh.exe interface ip add dns "Ethernet"  185.228.169.168 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Ethernet" static 2a0d:2a00:1:: primary
    %SystemRoot%System32
etsh.exe interface ipv6 add  dns "Ethernet"  2a0d:2a00:2::index=2        
    ECHO "Win7 Wifi"
    %SystemRoot%System32
etsh.exe interface ip set dns "Wi-Fi" static 185.228.168.168 primary
    %SystemRoot%System32
etsh.exe interface ip add  dns "Wi-Fi" 185.228.169.168 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Wi-Fi" static 2a0d:2a00:1:: primary
    %SystemRoot%System32
etsh.exe interface ipv6 add  dns "Wi-Fi" 2a0d:2a00:2::index=2 
    %SystemRoot%System32ipconfig.exe /flushdns
    ECHO "Flushing DNS..............." 
    %SystemRoot%System32ipconfig.exe /release 
    ECHO "Releasing DNS................." 
    %SystemRoot%System32ipconfig.exe /renew 
    ECHO "Renewing DNS............." 
    %SystemRoot%System32ipconfig.exe /all
    ECHO "Restarted Network Adapters and CHECK DNS Servers" 
    PAUSE
    PROMPT
    CLS    
GOTO END


GOTO START
:DNS_CloudFlare_Family_Win10
    ECHO "Changing Search Engine Results to Safe Family CloudFlare_Family_Win10"
    ECHO  ".............Changing IPV4 DNS Of This PC-Only CloudFlare_Family_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Wi-Fi" static 1.1.1.3 primary 
    %SystemRoot%System32
etsh.exe interface ipv4 add dnsservers "Wi-Fi" 1.0.0.3 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Wifi CloudFlare_Family_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Wi-Fi" static 2606:4700:4700::1113 primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Wi-Fi" 2606:4700:4700::1003 index=2
    ECHO  ".............Changing IPV4 DNS Of This PC-Only Ethernet CloudFlare_Family_Win10..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Ethernet" static 1.1.1.3 primary 
    %SystemRoot%System32
etsh.exe interface ipv4 add dnsservers "Ethernet" 1.0.0.3 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Ethernet CloudFlare_Family_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Wi-Fi" static 2606:4700:4700::1113 primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Wi-Fi" 2606:4700:4700::1113 primary
    ECHO  ".............Changing IPV4 DNS Of This PC-Only Local Area Connection CloudFlare_Family_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Local Area Connection" static  1.1.1.3 primary  
    %SystemRoot%System32
etsh.exe interface ipv4 add dnsservers "Local Area Connection" 1.0.0.3 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Local Area Connection CloudFlare_Family_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Local Area Connection" static 2606:4700:4700::1113 primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Local Area Connection" 2606:4700:4700::1003 index=2
    %SystemRoot%System32ipconfig.exe /flushdns
    ECHO "...................Flushing DNS..............." 
    %SystemRoot%System32ipconfig.exe /release 
    ECHO "....................Releasing DNS................." 
    %SystemRoot%System32ipconfig.exe /renew 
    ECHO ".......................Renewing DNS............." 
    %SystemRoot%System32ipconfig.exe /all
    ECHO "Restarted Network Adapters and CHECK DNS Servers" 
    PAUSE
    PROMPT
    CLS    
    ECHO "Changing Search Engine Results to Safe Family (CloudFlare Family DNS)."
    ECHO  " Changing DNS Of This PC-Only Wifi..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dns "Wi-Fi" 1.1.1.3 primary
    %SystemRoot%System32
etsh.exe interface ipv4 add dns "Wi-Fi" 1.0.0.3 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Wi-Fi" 2606:4700:4700::1113 primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dns "Wi-Fi" 2606:4700:4700::1003 index=2
    ECHO  " Changing DNS Of This PC-Only Ethernet ..............................................................."
    %SystemRoot%System32
etsh.exe interface ipv4 set dns "Wired Ethernet Connection" 1.1.1.3 primary
    %SystemRoot%System32
etsh.exe interface ipv4 add dns "Wired Ethernet Connection" 1.0.0.3 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Wired Ethernet Connection" 2606:4700:4700::1113 primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dns "Wired Ethernet Connection" 2606:4700:4700::1003 index=2
    ECHO " Changing DNS Of This PC-Only Local Area Connection.............................................."
    %SystemRoot%System32
etsh.exe interface ipv4 set dns "Local Area Connection" 1.1.1.3 primary
    %SystemRoot%System32
etsh.exe interface ipv4 add dns "Local Area Connection" 1.0.0.3 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Local Area Connection" 2606:4700:4700::1113 primary
    %SystemRoot%System32
etsh.exe interface ipv6 add dns "Local Area Connection" 2606:4700:4700::1003 index=2
    %SystemRoot%System32ipconfig.exe /flushdns
    ECHO "Flushing DNS..............." 
    %SystemRoot%System32ipconfig.exe /release 
    ECHO "Releasing DNS................." 
    %SystemRoot%System32ipconfig.exe /renew 
    ECHO "Renewing DNS............." 
    %SystemRoot%System32ipconfig.exe /all
    ECHO "Restarted Network Adapters and CHECK DNS Servers" 
    PAUSE
    PROMPT
    CLS

GOTO END

GOTO START
:CloudFlareDNS_Family_Shield_Win_7
   ECHO "Windows 7 Ethernet"
    %SystemRoot%System32
etsh.exe interface ip set dns "Ethernet" static 1.1.1.3  primary
    %SystemRoot%System32
etsh.exe interface ip add dns "Ethernet"  1.0.0.3 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Ethernet" static 2a0d:2a00:1:: primary
    %SystemRoot%System32
etsh.exe interface ipv6 add  dns "Ethernet"  2606:4700:4700::1003 index=2        
   ECHO "Win7 Wifi"
    %SystemRoot%System32
etsh.exe interface ip set dns "Wi-Fi" static 1.1.1.3 primary
    %SystemRoot%System32
etsh.exe interface ip add  dns "Wi-Fi"  1.0.0.3 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Wi-Fi" static 2a0d:2a00:1:: primary
    %SystemRoot%System32
etsh.exe interface ipv6 add  dns "Wi-Fi"  2606:4700:4700::1003 index=2
    %SystemRoot%System32ipconfig.exe /flushdns
    %SystemRoot%System32ipconfig.exe /flushdns
    ECHO "Flushing DNS..............." 
    %SystemRoot%System32ipconfig.exe /release 
    ECHO "Releasing DNS................." 
    %SystemRoot%System32ipconfig.exe /renew 
    ECHO "Renewing DNS............." 
    %SystemRoot%System32ipconfig.exe /all
    ECHO "Restarted Network Adapters and CHECK DNS Servers" 
    PAUSE
    PROMPT
    CLS

GOTO END


GOTO START
:GoogleDNS_Win10
   ECHO "Changing Search Engine Results to GoogleDNS_Win10."
    ECHO  " Changing DNS Of This PC-Only Wifi To GoogleDNS_Win10..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Wi-Fi" static 8.8.8.8 primary 
    %SystemRoot%System32
etsh.exe interface ipv4 add dnsservers "Wi-Fi" 8.8.4.4 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Wifi GoogleDNS_Win10g ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Wi-Fi" static 2001:4860:4860::8888 primary 
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Wi-Fi" 2a0d:2a00:2:: index=2 
    ECHO  ".............Changing IPV4 DNS Of This PC-Only Ethernet GoogleDNS_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Ethernet" static 8.8.8.8 primary 
    %SystemRoot%System32
etsh.exe interface ipv4 add dnsservers "Ethernet" 8.8.4.4 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Ethernet GoogleDNS_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Wi-Fi" static 2001:4860:4860::8888 primary 
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Wi-Fi" 2a0d:2a00:2:: index=2 
    ECHO  ".............Changing IPV4 DNS Of This PC-Only Local Area Connection GoogleDNS_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv4 set dnsservers "Local Area Connection" static 8.8.8.8 primary  
    %SystemRoot%System32
etsh.exe interface ipv4 add dnsservers "Local Area Connection" 8.8.4.4 index=2
    ECHO  ".............Changing IPV6 DNS Of This PC-Only Local Area Connection GoogleDNS_Win10 ..............................................................................." 
    %SystemRoot%System32
etsh.exe interface ipv6 set dnsservers "Local Area Connection" static 2001:4860:4860::8888 primary 
    %SystemRoot%System32
etsh.exe interface ipv6 add dnsservers "Local Area Connection" 2a0d:2a00:2:: index=2 
    %SystemRoot%System32ipconfig.exe /flushdns
    ECHO "...................Flushing DNS..............." 
    %SystemRoot%System32ipconfig.exe /release 
    ECHO "....................Releasing DNS................." 
    %SystemRoot%System32ipconfig.exe /renew 
    ECHO ".......................Renewing DNS............." 
    %SystemRoot%System32ipconfig.exe /all
    ECHO "Restarted Network Adapters and CHECK DNS Servers" 
    PAUSE
    PROMPT
    CLS    
    %SystemRoot%System32ipconfig.exe /flushdns
    ECHO "Flushing DNS..............." 
    %SystemRoot%System32ipconfig.exe /release 
    ECHO "Releasing DNS................." 
    %SystemRoot%System32ipconfig.exe /renew 
    ECHO "Renewing DNS............." 
    %SystemRoot%System32ipconfig.exe /all
    ECHO "Restarted Network Adapters and CHECK DNS Servers" 
    PAUSE
    PROMPT
    CLS

GOTO END

GOTO START
:GoogleDNS_Win_7
   ECHO "Windows 7 Ethernet"
    %SystemRoot%System32
etsh.exe interface ip set dns "Ethernet" static 8.8.8.8 primary
    %SystemRoot%System32
etsh.exe interface ip add dns "Ethernet" 8.8.4.4 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Ethernet" static 2001:4860:4860::8888 primary
    %SystemRoot%System32
etsh.exe interface ipv6 add  dns "Ethernet" 2001:4860:4860::8844 index=2        
   ECHO "Win7 Wifi"
    %SystemRoot%System32
etsh.exe interface ip set dns "Wi-Fi" static 8.8.8.8 primary
    %SystemRoot%System32
etsh.exe interface ip add  dns "Wi-Fi"  8.8.4.4 index=2
    %SystemRoot%System32
etsh.exe interface ipv6 set dns "Wi-Fi" static 2001:4860:4860::8888 primary
    %SystemRoot%System32
etsh.exe interface ipv6 add  dns "Wi-Fi" 2001:4860:4860::8844 index=2        
    %SystemRoot%System32ipconfig.exe /flushdns
    ECHO "Flushing DNS..............." 
    %SystemRoot%System32ipconfig.exe /release 
    ECHO "Releasing DNS................." 
    %SystemRoot%System32ipconfig.exe /renew 
    ECHO "Renewing DNS............." 
    %SystemRoot%System32ipconfig.exe /all
    ECHO "Restarted Network Adapters and CHECK DNS Servers" 
    PAUSE
    PROMPT
    CLS
GOTO END

GOTO START
:Check_DNS_Servers 
IPCONFIG /ALL
ECHO "CHECKOUT THE NEW DNS SERVERS DNS Servers" 
PAUSE
GOTO END


【讨论】:

  • ; 的行是什么?分号类似于普通空格、逗号、等号和 OEM 编码的不间断空格,解释为参数分隔符。因此,只有; 的行被解释为只有一个空格的行,这意味着只是无用地打开批处理文件,读取这样的行,解析它们,关闭批处理文件并且什么都不做。因此,只有分号的行只会稍微减慢批处理文件的执行速度。因此,我建议删除仅包含 ; 的所有行。
  • 最好引用具有完整限定文件名的所有可执行文件,以避免在处理批处理文件时一次又一次地搜索可执行文件netshipconfig 的大量文件系统访问。所以应该使用%SystemRoot%System32 etsh.exe 而不是仅仅使用netsh%SystemRoot%System32ipconfig.exe 而不是仅仅使用ipconfig 以避免在处理这个批处理文件时进行数十次不必要的文件系统访问,并且另外使批处理文件独立于环境变量@987654331 @ 和 PATHEXT。并使用%SystemRoot%System32opy.exe
  • 谢谢@Mofi,您的评论将被考虑并添加到脚本中,非常感谢
猜你喜欢
  • 2011-03-06
  • 1970-01-01
  • 2022-10-19
  • 2012-11-28
  • 2012-09-21
  • 1970-01-01
  • 2011-03-10
  • 2017-04-23
  • 2019-06-11
相关资源
最近更新 更多