已经解决了,呵呵
-
-
- @echo off
- @Setlocal ENABLEDELAYEDEXPANSION
- @set reg_path_id=
- @set reg_path=
- @set nic_id=
- @set nic_name=
- echo 获取本地网络连接名称...
- @for /f "usebackq tokens=7 delims=\" %%i in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards"`) do (
- set reg_path_id=%%i
- set "reg_path=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\!reg_path_id!"
- for /f "usebackq tokens=3" %%j in (`"reg query "!reg_path!" | find /i "ServiceName""`) do (
- set NIC_id=%%j
- for /f "usebackq skip=2 tokens=3" %%k in (`reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\!nic_id!" /v NTEContextList`) do (if not "%%k" == "\0" (Goto :nic_name))
- ))
- Goto :EOF
- :nic_name
- @if exist %temp%\reg.temp (del /q %temp%\reg.temp >nul)
- @reg export "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%nic_id%\Connection" %temp%\reg.temp >nul
- for /f "usebackq tokens=2 delims==" %%l in (`find /i "Name" %temp%\reg.temp`) do (
- set nic_name=%%l
- set nic_name=!nic_name:"=!
- )
- @if exist %temp%\reg.temp (del /q %temp%\reg.temp >nul)
- echo 您的网卡连接名称为:%nic_name%
- echo.
- echo 开始自动设置DNS地址...
- echo.
- echo 自动设置首选DNS地址(10.1.1.3)....
- Netsh interface IP set dns "%nic_name%" source=static 10.1.1.3 register=primary
- echo 自动设置备用DNS地址(10.1.1.4)....
- Netsh interface IP add dns "%nic_name%" 10.1.1.4
- echo.
- Echo 设置成功 按任一键后,就可以使用了……
- Pause>nul
-
复制代码
|