用VBS设置静态IP和DNS服务器地址的代码
2011-01-21 22:09
1046 查看
核心代码一:
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
相关文章推荐
- Centos 6 设置静态 IP 地址
- ubuntu修改静态IP、设置dns地址
- Windows Azure 设置虚拟机静态外网IP地址
- 设置静态ip的脚本代码
- 用vbs实现配置静态 IP 地址
- VBS 访问WMI读取IP地址,并将其设置为静态IP
- Windows Azure 设置虚拟机静态外网IP地址
- VBS获取外网IP地址并发送到指定邮箱的代码
- Java 实现根据 IP 地址获取地理位置的代码分享
- windows脚本设置网络IP地址
- Linux静态IP设置
- Centos 7 学习之静态IP设置
- VMware中CentOS设置静态IP的方法
- centos6.5配置静态IP 时,出现BCAST不能设置的问题
- Ubuntu中设置静态IP的方法介绍
- Linux设置静态IP
- linux 静态ip设置教程
- Ubuntu 静态ip的设置方法
- Linux:静态IP配置与防火墙设置
- ubuntu14.04设置静态ip