Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: How to get the local machine name


Message #1 by Clif Dunaway <csdunaway@y...> on Sat, 20 Jul 2002 15:42:34 -0700 (PDT)
Clif,

if you are using 2000/XP and you need more information about your computer,
drop this code in a standard bas module. It gives you all the netBios and
dns names associated to the local computer

Marco

-----------------------------------------------------------
Private Declare Function GetComputerNameEx Lib "kernel32" 
Alias "GetComputerNameExA" _
    (ByVal ltype As Long, ByVal lpBuffer As String, nSize As Long) As Long

Public Function ComputerNameNetBios() As String
    ComputerNameNetBios = cName(0)
End Function
Public Function ComputerNameDnsHostname() As String
    ComputerNameDnsHostname = cName(1)
End Function
Public Function ComputerNameDnsDomain() As String
    ComputerNameDnsDomain = cName(2)
End Function
Public Function ComputerNameDnsFullyQualified() As String
    ComputerNameDnsFullyQualified = cName(3)
End Function
Public Function ComputerNamePhysicalNetBios() As String
    ComputerNamePhysicalNetBios = cName(4)
End Function
Public Function ComputerNamePhysicalDnsHostname() As String
    ComputerNamePhysicalDnsHostname = cName(5)
End Function
Public Function ComputerNamePhysicalDnsDomain() As String
    ComputerNamePhysicalDnsDomain = cName(6)
End Function
Public Function ComputerNamePhysicalDnsFullyQualified() As String
    ComputerNamePhysicalDnsFullyQualified = cName(7)
End Function

Private Function cName(ByVal ltype As Long) As String
    Dim nm As String
    Dim lSize As Long
    lSize = 255
    nm = Space(lSize)
    Dim ret As Long
    ret = GetComputerNameEx(ltype, nm, lSize)
    If ret <> 0 And lSize <> 0 Then
        cName = Left$(nm, lSize)
    End If
End Function
-----------------------------------------------------------

  Return to Index