⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 电子书“Visual Basic 6 网络编程实例教程.rar”
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "系统是否启用了DHCP"
   ClientHeight    =   1650
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   2535
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1650
   ScaleWidth      =   2535
   StartUpPosition =   2  '屏幕中心
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   720
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   480
      Width           =   1455
   End
   Begin VB.CommandButton Command1 
      Caption         =   "运行(&R)"
      Height          =   375
      Left            =   720
      TabIndex        =   0
      Top             =   1080
      Width           =   1215
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "是否启用DHCP"
      Height          =   180
      Left            =   480
      TabIndex        =   2
      Top             =   240
      Width           =   1080
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
    If DhcpIsEnabled() Then
        Text1 = "是"
    Else
        Text1 = "否"
    End If
End Sub

Private Function DhcpIsEnabled() As Boolean
   Dim cbRequired   As Long
   Dim buff()       As Byte
   Dim Adapter      As IP_ADAPTER_INFO
   Dim AdapterStr   As IP_ADDR_STRING
   Dim ptr1         As Long
   Dim flag         As Long
   Call GetAdaptersInfo(ByVal 0&, cbRequired)
   If cbRequired > 0 Then
      ReDim buff(0 To cbRequired - 1) As Byte
      If GetAdaptersInfo(buff(0), cbRequired) = ERROR_SUCCESS Then
        '获取指向存放在buff()中数据的指针
         ptr1 = VarPtr(buff(0))
         Do While ptr1
           '将第一个网卡的数据复制到IP_ADAPTER_INFO结构中
            CopyMemory Adapter, ByVal ptr1, LenB(Adapter)
           '获取网卡数据
            With Adapter
              '设置flag值,确定网卡是否启动了DHCP
               flag = .uDhcpEnabled = 1
              '如果网卡启动了DHCP,则退出函数
               If flag = True Then Exit Do
              '若未启动DHCP,则检查其它网卡
               ptr1 = .dwNext
            End With
         Loop
      End If
   End If
   DhcpIsEnabled = flag
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -