CISA FotoGallery

Statistiche

Tot. visite contenuti : 927955
Home Articoli tecnici API NetBIOS o DNS_Name associato al Computer Locale

NetBIOS o DNS_Name associato al Computer Locale

Questa Funzione è la versione evoluta della chiamata API GetComputerName.
Consente di recuperare i nomi del PC inserito in una Rete stabiliti dal sistema allo startup.

CODICE

Private Enum COMPUTER_NAME_FORMAT
    ComputerNameNetBIOS
    ComputerNameDnsHostname
    ComputerNameDnsDomain
    ComputerNameDnsFullyQualified
    ComputerNamePhysicalNetBIOS
    ComputerNamePhysicalDnsHostname
    ComputerNamePhysicalDnsDomain
    ComputerNamePhysicalDnsFullyQualified
    ComputerNameMax
End Enum

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

Private Sub
Form_Load()
    ShowName ComputerNameNetBIOS, "NetBIOS name"
    ShowName ComputerNameDnsHostname, "DNS host name"
    ShowName ComputerNameDnsDomain, "DNS Domain"
    ShowName ComputerNameDnsFullyQualified, "Fully qualified DNS name"
    ShowName ComputerNamePhysicalNetBIOS, "Physical NetBIOS name"
End Sub

Private Sub
ShowName(lIndex As COMPUTER_NAME_FORMAT, Description As String)
    Dim Ret As Long, sBuffer As String
    
'Crea il Buffer
    
sBuffer = Space(256)
    Ret = Len(sBuffer)
    'estrae il nome del Computer
    
If GetComputerNameEx(lIndex, sBuffer, Ret) <> 0 And Ret > 0 Then
        
'stampa su screen
        
Debug.Print Description + ": " + Left$(sBuffer, Ret)
    End If
End Sub


Alessandro