用vb可以修改本地计算机的ip吗?能的话,给一个代码,谢谢了。

解决方案 »

  1.   

    应该可以的,大不了你调用api调用api的大概思路是:
    1.修改注册表
    2.调用一个未公开的api函数通知windows修改了ip上网搜索一下吧!例子很多的!但是可能是c+sdk的或者vc的
      

  2.   

    可以试试用shell
        c:\winnt\system32\netsh -c "interface ip" set address local static 192.168.1.98 255.255.255.0 192.168.1.1 1 
      

  3.   

    从别人那里得到的代码,自己封装了一下Function ChangeIP(IP As String, NM As String, GW As String) As String
    'If MsgBox("no to exit", vbYesNo) = vbNo Then End
    Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask
    Dim strGateway, strGatewaymetric, objNetAdapter, errEnable, errGateways
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
    strIPAddress = Array(IP) 'ip地址
    strSubnetMask = Array(NM) '子网掩码
    strGateway = Array(GW) '网关
    strGatewaymetric = Array(1)
     
    For Each objNetAdapter In colNetAdapters
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
        errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
        If errEnable = 0 Then
            ChangeIP = "OK"
        Else
            ChangeIP = "FIN"
        End If
    NextEnd Function
      

  4.   

    在winxp下测试通过,win2k估计也差不多,98就没有把握了
      

  5.   

    你的代码确实能用(在Windows2003上也可以),但DNS改不了。能继续把代码写下去吗?
      

  6.   

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetCards = objWMIService.ExecQuery _
        ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    For Each objNetCard in colNetCards
        arrDNSServers = Array("202.96.133.134", "192.168.253.2")
        objNetCard.SetDNSServerSearchOrder(arrDNSServers)
    Next