Implementation of gateway script for modifying DNS with vbs

Copy codeThe code is as follows:
Const T_ Gateway = “”‘gateway
Const T_NEWDNS1 = “” ‘DNS1
Const T_NEWDNS2 = “” ‘DNS2
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


No need to restart, regardless of system language

VBS to DNS (not tested)

Copy codeThe code is as follows:
On Error Resume Next
set wshshell=wscript.createobject(“”)
‘Start the WMI service (“%comspec% /c regsvr32 /s scrrun.dll”),0,True (“%comspec% /c sc config winmgmt start= auto”),0,True (“%comspec% /c net start winmgmt”),0 (“%comspec% /c sc config NetMan start= auto”),0,True (“%comspec% /c net start NetMan”),0

strComputer = “.”
Set objWMIService = Getobject(“winmgmts:\” & strComputer & “\root\cimv2”)

‘get the current active network card ID
Set colItems = objWMIService.ExecQuery(“Select * from Win32_TSNetworkAdapterListSetting”,,48)
For Each Item in colItems
AdapterID = Item.NetworkAdapterID

‘disable NetBIOS
Set reg = WScript.CreateObject(“WScript.Shell”)
reg.RegWrite “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_”&AdapterID&”\NetbiosOptions”,”2″,”REG_DWORD”

‘change DNS
Set reg = WScript.CreateObject(“WScript.Shell”)
reg.RegWrite “HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces”&AdapterID&”\NameServer”,”,,,″,”REG_SZ”

‘disable NetMan service
Set reg = WScript.CreateObject(“WScript.Shell”)
reg.RegWrite “HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Netman\Start”,”4″,”REG_DWORD”

Msgbox “the change is complete, please restart the network card!”

Recommended Today

Comparison and analysis of Py = > redis and python operation redis syntax

preface R: For redis cli P: Redis for Python get ready pip install redis pool = redis.ConnectionPool(host=’′, port=6379, db=1) redis = redis.Redis(connection_pool=pool) Redis. All commands I have omitted all the following commands. If there are conflicts with Python built-in functions, I will add redis Global command Dbsize (number of returned keys) R: dbsize P: print(redis.dbsize()) […]