用vbs实现配置静态 IP 地址
发布时间:2016-12-28 来源:查字典编辑
摘要:将计算机的IP地址设置为192.168.1.141,并将IP网关设置为192.168.1.100。脚本代码复制代码代码如下:strCompu...
将计算机的IP地址设置为192.168.1.141,并将IP网关设置为192.168.1.100。
脚本代码
复制代码 代码如下:
strComputer="."
SetobjWMIService=GetObject("winmgmts:"&strComputer&"rootcimv2")
SetcolNetAdapters=objWMIService.ExecQuery_
("Select*fromWin32_NetworkAdapterConfigurationwhereIPEnabled=TRUE")
strIPAddress=Array("192.168.1.141")
strSubnetMask=Array("255.255.255.0")
strGateway=Array("192.168.1.100")
strGatewayMetric=Array(1)
ForEachobjNetAdapterincolNetAdapters
errEnable=objNetAdapter.EnableStatic(strIPAddress,strSubnetMask)
errGateways=objNetAdapter.SetGateways(strGateway,strGatewaymetric)
IferrEnable=0Then
WScript.Echo"TheIPaddresshasbeenchanged."
Else
WScript.Echo"TheIPaddresscouldnotbechanged."
EndIf
Next