查看: 396  |  回复: 0
  VB6 获取NetBIOS名,DNS主机名
楼主
发表于 2023年4月14日 15:19
Option Explicit

Enum COMPUTER_NAME_FORMAT
    ComputerNameNetBIOS
    'NetBIOS名
    ComputerNameDnsHostname
    'DNS主机名
    ComputerNameDnsDomain
    'DNS域名
    ComputerNameDnsFullyQualified
    '完全修饰DNS名
    ComputerNamePhysicalNetBIOS
    '物理的NetBIOS名
    ComputerNamePhysicalDnsHostname
    '物理的DNS主机名
    ComputerNamePhysicalDnsDomain
    '物理的DNS主机名
    ComputerNamePhysicalDnsFullyQualified
    '物理的完全修饰DNS名
    ComputerNameMax
    '未使用
End Enum

Private Declare Function GetComputerNameEx Lib "kernel32.dll" _
                                           Alias "GetComputerNameExA" _
                                           (ByVal NameType As Long, _
                                            ByVal lpBuffer As String, _
                                            lpnSize As Long) As Long

Private Sub Form_Load()
    Dim lngExtComputerNameType As Long
    Dim strExtComputerName As String * 128
    Dim lngWin32apiResultCode  As Long

    lngExtComputerNameType = ComputerNameNetBIOS
    lngWin32apiResultCode = GetComputerNameEx(lngExtComputerNameType, _
                            strExtComputerName, _
                            Len(strExtComputerName))

    Dim str_Names As String

    If lngWin32apiResultCode <> 0 Then
        str_Names = str_Names + "NetBIOS名:"
        str_Names = str_Names + Left$(strExtComputerName, _
                    InStr(strExtComputerName, _
                    vbNullChar) - 1) + Chr$(13)
                    
    End If

    lngExtComputerNameType = ComputerNameDnsHostname
    lngWin32apiResultCode = GetComputerNameEx(lngExtComputerNameType, _
                            strExtComputerName, _
                            Len(strExtComputerName))

    If lngWin32apiResultCode <> 0 Then
    
        str_Names = str_Names + "DNS主机名:"
        str_Names = str_Names + Left$(strExtComputerName, _
                    InStr(strExtComputerName, _
                    vbNullChar) - 1)
                    
    End If

    MsgBox str_Names
End Sub


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com