南瓜园

 找回密码
 注册
查看: 1533|回复: 2

修改计算机IP脚本

[复制链接]
发表于 2010-5-5 17:43:19 | 显示全部楼层 |阅读模式
Set objShell = CreateObject("Wscript.Shell")

IP = InputBox ("输入新的IP地址","IP地址")

NM="255.255.255.0" '子网掩码

GW= "192.168.26.253"  '网关根据自己的实际情况录入,见下面的说明文字

MDNS="192.168.26.12" '首选DNS

SDNS="202.103.96.112"  '备用DNS

msgbox ChangeIP(IP,NM,GW,MDNS,SDNS)

Function ChangeIP(IP, NM, GW, MDNS, SDNS)

  Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask

  Dim strGateway, strGatewaymetric, strDNS, objNetAdapter, errEnable, errGateways, errDNS

  strComputer = "."

  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

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

  strIPAddress=Array(IP)

  strSubnetMask=Array(NM)

  strGateway=Array(GW)

  strDNS = Array(MDNS, SDNS)

  strGatewaymetric = Array(1)

  For Each objNetAdapter In colNetAdapters

    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

    errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)

    If errEnable = 0 And errGateways = 0 And errDNS = 0 Then

      ChangeIP = "设置成功"

    Else

      If errEnable = 0 Then

          ChangeIP = "IP地址和子网掩码设置成功, "

      Else

          ChangeIP = "IP地址或子网掩码设置失败, "

      End If

      If errGateways = 0 Then

          ChangeIP = ChangeIP & "默认网关设置成功, "

      Else

          ChangeIP = ChangeIP & "默认网关设置失败, "

      End If

      If errDNS = 0 Then

          ChangeIP = ChangeIP & "DNS设置成功"

      Else

          ChangeIP = ChangeIP & "DNS设置失败"

      End If

    End If

  Next

  End Function
发表于 2010-5-17 17:26:48 | 显示全部楼层
教教怎么用的啊?
发表于 2010-5-24 12:43:43 | 显示全部楼层
[s:10]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

请大家牢记南瓜园网址 www.nan2008.com

QQ|小黑屋|手机版|Archiver|南瓜园

GMT+8, 2024-12-19 12:36 , Processed in 0.089336 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表