看看这段对你有没有帮助.
主窗体代码:
Dim gintNetworkAdapter As LongPrivate Namespace As SWbemServices
Private Method As SWbemMethod
'Default System Address
Const SystemAddress = "127.0.0.0"
Private Sub cboAdapter_Click()
'清除所有控件
'ClearAll Controls
    Call clearall
'取得被选择适配器的配置情况
'Get Configuration for the selected adapter    Call GetIPConfig(cboAdapter.ItemData(cboAdapter.ListIndex))
'为适配器设置一个公有变量
'Set a Global Variable for the selected adapter
    gintNetworkAdapter = cboAdapter.ItemData(cboAdapter.ListIndex)
End SubPrivate Sub cmdChgDNSServer_Click()
On Error Resume Next
Dim Adapter As Object
'改变 DNS 服务器
Set Adapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & gintNetworkAdapter & "")
If lblDNSServers.Tag = 0 Then
    lblDNSServers = Adapter.DNSServerSearchOrder(1)
    lblDNSServers.Tag = 1
Else
     lblDNSServers = Adapter.DNSServerSearchOrder(0)
     lblDNSServers.Tag = 0
End IfSet Adapter = Nothing
End SubPrivate Sub cmdOK_Click()
    End
End SubPrivate Sub cmdRelease_Click()
    On Error Resume Next
    Dim ReleaseLease As Object
    Set ReleaseLease = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & gintNetworkAdapter & "")      ReleaseLease.ReleaseDHCPLease
'清除索引
'Clear Info
        Call clearall
'关闭/打开 按钮
'Disable/Enable Buttons
        cmdRenew.Enabled = True
        cmdRelease.Enabled = False
        
    Set ReleaseLease = Nothing
End Sub
 Sub GetAdapterData()
On Error Resume Next
    
    Dim Adapter As SWbemObject
    Dim NIC As SWbemObject
   
    '列举实例
    'Enumerate the instances
    
    Set NICS = Namespace.InstancesOf("Win32_NetworkAdapterConfiguration")        For Each NIC In NICS
        
        
        ' Use the RelPath property of the instance path
        Set NIC = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=Adapter.Path_.RelPath")
        
        '列举出所有适配器
        'Fill the Adapter with all the adapters
        cboAdapter.AddItem NIC.Description
        cboAdapter.ItemData(cboAdapter.NewIndex) = NIC.Index
        Next
        cboAdapter.Text = cboAdapter.List(0)
         
    Set NICS = Nothing
End SubPrivate Sub cmdRenew_Click()
Me.MousePointer = vbHourglass
On Error Resume Next
    Dim RenewLease As Object
    Set RenewLease = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & gintNetworkAdapter & "")'Renew DHCP Lease for the selected adapter
      RenewLease.RenewDHCPLease'Clear Info
    Call clearall'Get Adapter Congiguration
    Call GetIPConfig(gintNetworkAdapter)'Disable/Enable Buttons
    cmdRenew.Enabled = True
    cmdRelease.Enabled = True
    
    Set RenewLease = Nothing
Me.MousePointer = vbDefault
End SubPrivate Sub Form_Load()
Set Namespace = GetObject("winmgmts:")
'取得机器适配器
'Get Machine Adapters
    GetAdapterData'读取缺省的适配器信息
'Load Default Adapter Information
    Call GetIPConfig(0)
End SubSub GetIPConfig(intNetworkAdapter As Long)
On Error Resume Next
Dim Adapter As Object
'清除适配器地址
'Clear Adapter Address
    lblAdapterAddress.Caption = ""
Set Adapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & intNetworkAdapter & "")'填写适配器和主机信息
'Fill Adapter and Host Information
   With Adapter
        lblAdapterAddress.Caption = .MACAddress
        If Not .IPADDRESS(intNetworkAdapter) = SystemAddress Then _
        lblIPAddress.Caption = .IPADDRESS(intNetworkAdapter) _
        Else lblIPAddress.Caption = "0.0.0.0"
        If Not .IPSubnet(intNetworkAdapter) = SystemAddress Then _
        lblSubnetMask.Caption = .IPSubnet(intNetworkAdapter) _
        Else lblSubnetMask.Caption = "0.0.0.0"
        If Not .DefaultIPGateway(intNetworkAdapter) = SystemAddress Then _
        lblDefGateway.Caption = .DefaultIPGateway(intNetworkAdapter) _
        Else lblDefGateway.Caption = ""
        lblDHCPServer.Caption = .DHCPServer
        If Not .WINSPrimaryServer = SystemAddress Then _
        lblPrimaryWins.Caption = .WINSPrimaryServer _
        Else lblPrimaryWins.Caption = ""
        If Not .WINSSecondaryServer = SystemAddress Then _
        lblSecondaryWins.Caption = .WINSSecondaryServer _
        Else lblSecondaryWins.Caption = ""
        lblLeaseObtained.Caption = ParseDate(.DHCPLeaseObtained)
        lblLeaseExpires.Caption = ParseDate(.DHCPLeaseExpires)
        lblHostName.Caption = .DNSHostName & "." & .DNSdomain
        lblDNSServers.Caption = .DNSServerSearchOrder(intNetworkAdapter)
        lblDNSServers.Tag = 0
'如果打开了DHCP
'DHCP Enabled
        If .DHCPEnabled = True Then
            chkDHCPEnabled.Value = 1
        Else
            chkDHCPEnabled.Value = 0
        End If
           
    End With
Set Adapter = Nothing
End Sub
Function ParseDate(sDateString As String) As StringDim sParseDate As String
Dim sParseTime As StringIf sDateString = "" Then
    ParseDate = ""
Else
'从字符串中分析数据和时间
'Parse Date and Time from string
    sParseDate = Left(sDateString, 8)
    sParseTime = Right(Left(sDateString, 14), 6)'分析读到的数据和时间
'Parse to readable Date and time
    ParseDate = Mid(sParseDate, 5, 2) & "/" & Mid(sParseDate, 7, 2) & "/" & Mid(sParseDate, 1, 4) & "   " & Mid(sParseTime, 1, 2) & ":" & Mid(sParseTime, 3, 2) & ":" & Mid(sParseTime, 5, 2)
End If
End Function
Sub clearall()
Dim Control    For Each Control In Me.Controls
        If TypeOf Control Is Label Then
            If Not Control.Tag = "NOCLEAR" Then
               Control.Caption = ""
            End If
        End If
    If TypeOf Control Is CheckBox Then Control.Value = 0
    Next Control
    
    lblIPAddress = "0.0.0.0"
    lblSubnetMask = "0.0.0.0"
    
End Sub
模块代码:
Option Explicit
'API to Get a Windows Version
Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
                     (ByRef lpVersionInformation As OSVERSIONINFO) As LongPublic Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type' Returns Version of Windows as a String
' NOTE: Win95 returns "4.00"
        'Win98 returns "4.10"
        'WinNT returns ""
        'Win2000 returns "5.00"Function WindowsVersion() As String
    Dim osInfo As OSVERSIONINFO
    
    osInfo.dwOSVersionInfoSize = Len(osInfo)
    GetVersionEx osInfo
    
    WindowsVersion = osInfo.dwMajorVersion & "." & Right$("0" & Format$ _
        (osInfo.dwMinorVersion), 2)
        
End Function
Sub Main()
'Check Windows Version to make sure Windows 2000 is running
If Not WindowsVersion = "5.00" Then
    MsgBox "IP Wizard is only designed for the Windows 2000 Operating System!", vbCritical
    End
Else
    Load frmIPWizard
    frmIPWizard.Show
End If
End Sub

解决方案 »

  1.   

    这段程序含有窗体,可以麻烦你将程序发到[email protected]吗?
      

  2.   

    1)可 修改 注册表。 你去 win2k 的组策略 中看看。
    2)第2个问题嘛, …………………… 
       我先问你: 如果 你的IP 是 电信动态 分配的,比如拨号上网。IP 能改吗?
       回答显然是 不能, 除非你重新 拨号。
       所以 这个 问题 ……
      

  3.   

    问题一其实是怎样禁用和启用网卡(通过程序而不是手工,而且不用重启即时生效)
    问题二也是指网卡对应的TCP/IP协议
      

  4.   

    真不知道 visualbaby(好好学习天天向上) 笑什么?
    如果懂的话,不妨指教指教
    如果不懂的话,请不要这么傻
      

  5.   

    to 楼上:
    没法解释,请看
    回复人: sonicdater(发呆呆(我答问题*不吵架*因为我呆)) (  ) 信誉:64  2002-3-9 11:59:24  得分:0  
     
     
      1)可 修改 注册表。 你去 win2k 的组策略 中看看。 
    2)第2个问题嘛, …………………… 
    我先问你: 如果 你的IP 是 电信动态 分配的,比如拨号上网。IP 能改吗? 
    回答显然是 不能, 除非你重新 拨号。 
    所以 这个 问题 …… 
     
    不过,抱歉,我笑得是傻了一点!!!
      

  6.   

    如何打开拨号网络。由于拨号网络不是一个可执行文件,所以不能用 “Shell 可执行文件”的方式来打开。要启动拨号网络,需借助 Explorer ,方法如下: Shell "Explorer ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\" & "::{992CFFA0-F557-101A-88EC-00DD010CCC48}", vbNormalFocus
    ---- 但若是要启动拨号网络中的某一个连接,则需借助rundll.exe 及 rnaui.dll来启动,方法如下(假定连接名称为163): Shell "rundll rnaui.dll,RnaDial 163", vbNormalFocus
    ---- 说明:在以上叙述中,“,RnaDial 163”这部分不要插入额外的空格,大小写也不要任意更改。 ---- 上面仅仅假定了连接名称,但实际编程中我们是不知道其名称的,如何取得默认的连接名称并启动它呢?这里我们可利用注册表来达到目的。完整程序如下: ---- 在窗体上放置一个命令按钮(名称为 cmdCallConnect),下面为代码部份: Option Explicit
          
    '有关注册的API声明
    Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As LongPrivate Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal szData As String, ByRef lpcbData As Long) As LongPrivate Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
    '常数
    Const HKEY_CURRENT_USER = &H80000001
    Const ERROR_SUCCESS = 0&
          
    Private Sub cmdCallConnect_Click()
    '启动默认拨号连接
    Shell "rundll rnaui.dll,RnaDial " + GetConnect, vbNormalFocus
    End Sub
          
    Public Function GetConnect() As String
    Dim hKey As Long
    Dim SubKey As String
    hKey = HKEY_CURRENT_USER  '主键
    SubKey = "RemoteAccess"   '子键
    '取得默认连接名
    GetConnect = GetRegValue(hKey, SubKey, "Default")
    End FunctionPublic Function GetRegValue(hKey As Long, lpszSubKey As String, szKey As String) As Variant
    On Error GoTo ErrorRoutineErr:
    Dim phkResult As Long
    Dim lResult As Long
    Dim szBuffer As String
    Dim lBuffSize As Long'创建缓冲区
    szBuffer = Space(255)
    lBuffSize = Len(szBuffer)'打开注册键
    RegOpenKeyEx hKey, lpszSubKey, 0, 1, phkResult'查询结果
    lResult = RegQueryValueEx(phkResult,szKey, 0, 0, szBuffer,lBuffSize)'关闭注册键
    RegCloseKey phkResult'返回结果
    If lResult = ERROR_SUCCESS Then
    GetRegValue = Left(szBuffer, lBuffSize - 1)
    Else
    GetRegValue = ""
    End If
    Exit FunctionErrorRoutineErr:
    GetRegValue = ""
    End Function
    以上程序在 WIN98,VB6.0 下调试通过
      

  7.   

    2)第2个问题嘛, …………………… 
    我先问你: 如果 你的IP 是 电信动态 分配的,比如拨号上网。IP 能改吗? 
    回答显然是 不能, 除非你重新 拨号。 
    所以 这个 问题 …… 反正我是不会
    如果是局域网内部ip,如果你是网管,当然简单了!!!!!
      

  8.   

    1. 禁用或启用网卡,可以在设备管理器选择要操作的网卡,选择禁用/启用,确定即可,是不需要重启的
    2. 我已经说过了我用的是网卡
       对于win98可以在网上邻居->属性->相应网卡的TCP/IP协议->属性->IP地址里面修改(需要重启)
       对于win2000可以在网上邻居->属性->相应网卡的连接->属性->TCP/IP协议->属性->IP地址里面修改(不需要重启)而我问的问题就是怎样用程序代替这些操作而已
      

  9.   

    现在明白你的意思了,不过第一个问题好像vb..........够呛!!!
    不过我有一篇文章:不知道行不行,拿出来给你参考:在win98里面,在程序里面实现对一个设备的禁用和启用(win2000是肯定是不行的) 
    就用串口为例子吧 
    比如我们要禁用串口com1 
    我们可以在设备列表里面选中Com1然后在他的属性里面选择禁用 
    这个时候在其实windows就会发出WM_DEVICECHANGE这消息,最重要的是也在注册表 
    里面产生了如下的键 
    在\HKEY_LOCAL_MACHINE\Config\0001\Enum\BIOS\*PNP0501\下出现用户变更设备配置的 
    键值,在握的机器里面是0B(不同的机器可能会不同),这个时候他的键CSConfigFlags的键值 
    为 01 00 00 00 
    如果我们现在把com1启用,这个时候再来看看CSConfigFlags的键值,这时候变成了 
    00 00 00 00 
    所以我在程序中只要修改这个CSConfigFlags的键值就可以实现了com1的禁用和启用了.我想,如果你知道网卡在注册表里的相关信息的话,也可以仿效!!!