用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

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

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. MySQL字符集与排序方式
  2. Python pdfplumber内存泄露问题解决方案
  3. 用VBS控制鼠标(获取鼠标坐标、鼠标移动、鼠标单击、鼠标双击、鼠标右击)
  4. PHP base_convert函数的一个有趣现象
  5. Msxml2.XMLHTTP Msxml2.ServerXMLHTTP与缓存

2 条评论 发表在“用VBS设置静态IP和DNS服务器地址”上

  1. linkanyway说道:

    膜拜, 师傅!

  2. 法拉利BEYOND说道:

    这个要是能提供批处理代码就更好了,哈哈,个人觉得黑底白字的玩意也很智能

留下回复