修改计算机IP脚本
Set objShell = CreateObject("Wscript.Shell")IP = InputBox ("输入新的IP地址","IP地址")
NM="255.255.255.0" '子网掩码
GW= "192.168.26.253"'网关根据自己的实际情况录入,见下面的说明文字
MDNS="192.168.26.12" '首选DNS
SDNS="202.103.96.112"'备用DNS
msgbox ChangeIP(IP,NM,GW,MDNS,SDNS)
Function ChangeIP(IP, NM, GW, MDNS, SDNS)
Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask
Dim strGateway, strGatewaymetric, strDNS, objNetAdapter, errEnable, errGateways, errDNS
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress=Array(IP)
strSubnetMask=Array(NM)
strGateway=Array(GW)
strDNS = Array(MDNS, SDNS)
strGatewaymetric = Array(1)
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
If errEnable = 0 And errGateways = 0 And errDNS = 0 Then
ChangeIP = "设置成功"
Else
If errEnable = 0 Then
ChangeIP = "IP地址和子网掩码设置成功, "
Else
ChangeIP = "IP地址或子网掩码设置失败, "
End If
If errGateways = 0 Then
ChangeIP = ChangeIP & "默认网关设置成功, "
Else
ChangeIP = ChangeIP & "默认网关设置失败, "
End If
If errDNS = 0 Then
ChangeIP = ChangeIP & "DNS设置成功"
Else
ChangeIP = ChangeIP & "DNS设置失败"
End If
End If
Next
End Function 教教怎么用的啊?
页:
[1]