欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用vbs实现修改dns的网关脚本

程序员文章站 2022-03-07 12:37:54
复制代码 代码如下:const t_gateway = "1.1.1.1" '网关 const t_newdns1 = "2.2.2.2" 'dns1 const t_ne...
复制代码 代码如下:

const t_gateway = "1.1.1.1" '网关
const t_newdns1 = "2.2.2.2" 'dns1
const t_newdns2 = "3.3.3.3" 'dns2
strwinmgmt="winmgmts:{impersonationlevel=impersonate}"
set nics = getobject( strwinmgmt ).instancesof("win32_networkadapterconfiguration")
for each nic in nics
if nic.ipenabled then
nic.setdnsserversearchorder array(t_newdns1,t_newdns2)
nic.setgateways array(t_gateway)
end if
next
 

无须重新启动,不管系统语言

vbs改dns(未测试):

复制代码 代码如下:

on error resume next
temp=0
set wshshell=wscript.createobject("wscript.shell")
'启动wmi服务
wshshell.run ("%comspec% /c regsvr32 /s scrrun.dll"),0,true
wshshell.run ("%comspec% /c sc config winmgmt start= auto"),0,true
wshshell.run ("%comspec% /c net start winmgmt"),0
wshshell.run ("%comspec% /c sc config netman start= auto"),0,true
wshshell.run ("%comspec% /c net start netman"),0

strcomputer = "."
set objwmiservice = getobject("winmgmts:\" & strcomputer & "\root\cimv2")

'得到当前活动网卡id
set colitems = objwmiservice.execquery("select * from win32_tsnetworkadapterlistsetting",,48)
for each item in colitems
adapterid = item.networkadapterid
next

'禁netbios
set reg = wscript.createobject("wscript.shell")
reg.regwrite "hkey_local_machine\system\currentcontrolset\services\netbt\parameters\interfaces\tcpip_"&adapterid&"\netbiosoptions","2","reg_dword"

'更改dns
set reg = wscript.createobject("wscript.shell")
reg.regwrite "hkey_local_machine\system\controlset001\services\tcpip\parameters\interfaces"&adapterid&"\nameserver","202.96.128.68,202.96.128.143,202.96.128.166,202.96.128.86","reg_sz"

'禁netman服务
set reg = wscript.createobject("wscript.shell")
reg.regwrite "hkey_local_machine\system\controlset001\services\netman\start","4","reg_dword"

msgbox "更改完成,请重启网卡!"