Option Compare Database

Option Explicit

 

Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

 

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

 

Function CompName()

    ' returns: machine name, e.g.:

    '   MONORAILPC

    Dim s As String, n As Long

    n = 255

    s = Space(255)

    If GetComputerName(s, n) > 0 Then

        CompName = Left(s, n)

    End If

End Function

 

Function UserName()

    ' returns: user name, e.g.:

    '   William Mitchell

    Dim s As String, n As Long

    n = 255

    s = Space(255)

    If GetUserName(s, n) > 0 Then

        UserName = Left(s, n)

    End If

End Function