Attribute VB_Name = "Module1"
Declare Function WNetGetUser& Lib "Mpr" Alias "WNetGetUserA" (lpName As Any, ByVal lpUserName$, lpnLength&)
Public Const MAX_COMPUTERNAME_LENGTH As Long = 15&
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetMachineName() As String

Dim plngSize As Long

Dim pstrBuffer As String

    pstrBuffer = Space$(MAX_COMPUTERNAME_LENGTH + 1)

    plngSize = Len(pstrBuffer)

    If GetComputerName(pstrBuffer, plngSize) Then

        GetMachineName = Left$(pstrBuffer, plngSize)

    End If

End Function


Public Function GetMachineUserName() As String

Dim pstrUserName As String

Dim plngUserNameLen As Long

Dim plngReturn As Long

    pstrUserName = Space(256)

    plngUserNameLen = Len(pstrUserName)

    plngReturn = WNetGetUser(ByVal 0&, pstrUserName, plngUserNameLen)

    If plngReturn = 0 Then

        ' Success - strip off the null.

        GetMachineUserName = Left(pstrUserName, InStr(pstrUserName, Chr(0)) - 1)

        Else

            GetMachineUserName = ""

    End If

End Function


