Code:
Option Compare Database
Option Explicit
Declare PtrSafe Function apiGetUserName Lib "advapi32" Alias "GetUserNameA" (ByVal buffer As String, BufferSize As Long) As Long
Declare PtrSafe Function apiGetComputerName Lib "Kernel32" Alias "GetComputerNameA" (ByVal buffer As String, BufferSize As Long) As Long
Function GetUserName() As String
'Wrapper for GetUserName API call.
'
'Procedure Syntax
'Dim strUserName As String
'strUserName = GetUserName
'Procedure Syntax
'
Dim strName As String
Dim lngSize As Long
Dim lngRetVal As Long
strName = Space(15)
lngSize = 15
lngRetVal = apiGetUserName(strName, lngSize)
GetUserName = Left$(strName, lngSize - 1)
End Function
Function GetComputerName() As String
'Wrapper for GetComputerName API call.
'
'Procedure Syntax
'Dim strComputerrName As String
'strComputerName = GetComputerName
'Procedure Syntax
'
Dim strName As String
Dim lngSize As Long
strName = Space(16)
lngSize = 16
If apiGetComputerName(strName, lngSize) Then
GetComputerName = Left$(strName, lngSize)
Else
GetComputerName = vbNullString
End If
End Function