欢迎来到工商注册核名查询系统!

vb

当前位置:主页 > 软件编程 > vb >

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

来源:本站原创|时间:2022-11-25|栏目:vb|

核心代码一:

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

更多vb

您可能感兴趣的文章

阅读排行

本栏相关

随机阅读

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 工商注册核名查询系统 版权所有