圆月山庄资源网 Design By www.vgjia.com

核心代码一:

strIPAddress = Array("192.168.0.148") 
strSubnetMask = Array("255.255.255.0") 
strGateway = Array("192.168.0.1") 
strGatewayMetric = Array(1) 
arrDNSServers = Array("192.168.0.1","192.168.0.2") 
strComputer = "." 

Set objWMIService = GetObject("winmgmts:" _ 
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Set colNetAdapters = objWMIService.ExecQuery _ 
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") 

For Each objNetAdapter in colNetAdapters 
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) 
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) 
errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers) 
If errEnable = 0 Then 
WScript.Echo "The IP address has been changed." 
Else 
WScript.Echo "The IP address could not be changed." 
End If 
Next 

记得把参数改成自己想要的。

代码二:

将计算机的 IP 地址设置为 192.168.1.111,并将 IP 网关设置为 192.168.1.1。

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\" & strComputer & " ootcimv2") 
Set colNetAdapters = objWMIService.ExecQuery _ 
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") 
strIPAddress = Array("192.168.1.111") 
strSubnetMask = Array("255.255.255.0") 
strGateway = Array("192.168.1.1") 
strGatewayMetric = Array(1) 
For Each objNetAdapter in colNetAdapters 
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) 
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) 
If errEnable = 0 Then 
WScript.Echo "The IP address has been changed." 
Else 
WScript.Echo "The IP address could not be changed." 
End If 
Next

原文:http://demon.tw/programming/vbs-modify-ip-dns-setting.html

标签:
VBS,IP,DNS

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com