Find the Computer Name

The GetComputerName function returns the name of the computer. It does not return the fully qualified domain name (FQDN) for computers that are joined to a domain.

Private Declare Function GetComputerName _

Lib "kernel32.dll" Alias "GetComputerNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long

Private Const MAX_COMPUTERNAME_LENGTH = 31

Function GetMachineName() As String Dim strComputerName As String Dim lngSize As Long strComputerName = Space(MAX_COMPUTERNAME_LENGTH) & Chr(0) lngSize = MAX_COMPUTERNAME_LENGTH + 1

If GetComputerName(strComputerName, lngSize) <> 0 Then GetMachineName = Left(strComputerName, lngSize)

Else

GetMachineName = "" End If End Function

0 0

Post a comment