Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = WshNetwork.ComputerName
Set WshNetwork = nothing
const IPADD = "172.16.1.139"
const Netmask = "255.255.255.0"
const Gateway = "172.16.1.1"
const Pdns = "172.16.1.10"
const Sdns = "172.16.1.12"
const dnsdetail1 = "nts01.worldchina.com.hk"
const dnsdetail2 = "greensward.com.hk"
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(IPADD)
strSubnetMask = Array(Netmask)
strGateway = Array(Gateway)
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "IP地址已修正!"
Else
WScript.Echo "IP地址未修改!"
End If
Next
Set colNetCards = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
arrDNSServers = Array(Pdns,Sdns)
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Wscript.Echo "DNS服務器地址已添加!"
Next
Set colNetCards = nothing
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
arrDNSSuffixes = Array(dnsdetail1, dnsdetail2)
objNetworkSettings.SetDNSSuffixSearchOrder(arrDNSSuffixes)
Wscript.Echo "DNS服務器尾碼已添加!"
Set objNetworkSettings = nothing
Set objWMIService = nothing
本文介绍了一段VBScript脚本,用于自动配置Windows系统的网络设置,包括静态IP地址、子网掩码、默认网关及DNS服务器等。通过WMI(Windows Management Instrumentation)接口实现对网络适配器配置的修改。

471

被折叠的 条评论
为什么被折叠?



