首页 /编程语言和算法/VB6/ASP
 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


 
全部回复(0)
首页 | 电脑版 |