首页 > 编程 > VBScript > 正文

用VBS设置静态IP和DNS服务器地址的代码

2020-06-26 18:25:05
字体:
来源:转载
供稿:网友
用VBS设置静态IP和DNS服务器地址的代码,今天别人问我的,怕以后忘记,记录下来。
 
复制代码代码如下:

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 

记得把参数改成自己想要的。 
原文:http://demon.tw/programming/vbs-modify-ip-dns-setting.html

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表