zoukankan      html  css  js  c++  java
  • VB设置网卡的IP地址

    在菜单中的【工程】—【引用】下,添加“Microsoft WMI Scripting V1.1 Library”,然后在Form1窗体上添加1个Combo1、Text1(0)、Text1(1)、Text1(2)、Text1(3)和Command1、Command2,代码如下:

    Option Explicit
    Dim objSWbemServices As SWbemServices
    Dim objSWbemObjectSet As SWbemObjectSet
    Dim objSWbemObject As SWbemObject
    'Text1(0)为IP地址、Text1(1)为子网掩码、Text1(2)为缺省网关、Text1(3)为DNS

    Private Sub Form_Load()
        
    Set objSWbemServices = GetObject("winmgmts:")
        
    Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
        
    For Each objSWbemObject In objSWbemObjectSet
            Combo1.AddItem objSWbemObject.Description   
    '添加本机上已经安装了TCP/IP协议的网卡
        Next
        Combo1.Text 
    = Combo1.List(0)
        Combo1.ListIndex 
    = 0
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
        
    Set objSWbemServices = Nothing
        
    Set objSWbemObjectSet = Nothing
        
    Set objSWbemObject = Nothing
    End Sub

    '当选择了网卡后,显示当前所选网卡的设置
    Private Sub Combo1_Click()
        
    Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
        
    For Each objSWbemObject In objSWbemObjectSet
            
    If objSWbemObject.DHCPEnabled Then
                Text1(
    0).Text = ""
                Text1(
    1).Text = ""
                Text1(
    2).Text = ""
                
    If IsNull(objSWbemObject.DNSServerSearchOrder) Then
                    Text1(
    3).Text = ""
                
    Else
                    Text1(
    3).Text = objSWbemObject.DNSServerSearchOrder(0)
                
    End If
            
    Else
                Text1(
    0).Text = objSWbemObject.IPAddress(0)
                Text1(
    1).Text = objSWbemObject.IPSubnet(0)
                Text1(
    2).Text = objSWbemObject.DefaultIPGateway(0)
                Text1(
    3).Text = objSWbemObject.DNSServerSearchOrder(0)
            
    End If
        
    Next
    End Sub

    '设置网卡的IP地址、子网掩码、缺省网关和DNS
    Private Sub Command1_Click()
        
    Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
        
    For Each objSWbemObject In objSWbemObjectSet
            objSWbemObject.EnableStatic 
    Array(Text1(0).Text), Array(Text1(1).Text)
            objSWbemObject.SetGateways 
    Array(Text1(2).Text)
            objSWbemObject.SetDNSServerSearchOrder 
    Array(Text1(3).Text)
        
    Next
    End Sub

    Private Sub Command2_Click()
        Unload Me
    End Sub

     

  • 相关阅读:
    中国跨境电商物流难题的三大解决方案
    美团外卖实时数仓建设实践
    美团商品知识图谱的构建及应用
    c++动态创建二维数组
    小鱼儿fish C#获取数组大小
    C#中定义数组--字符串及数组操作
    warning LNK4070的解决办法
    C++ 中 ZeroMemory、memset 危险需慎用
    C++中new和delete来创建和释放动态数组
    VS调试时查看动态数组的全部元素
  • 原文地址:https://www.cnblogs.com/findw/p/1993083.html
Copyright © 2011-2022 走看看