Many API calls such as GetComputerName and GetUserName can be used fairly easily
to get common information... once you know how. This example shows you how to
get the Computer Name, but could easily be adapted for GetUserName.
Private Declare Function apiGetComputerName Lib "kernel32"
Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)
As Long
Private Function GetPCName() As String
Dim sResult As String
'// Computer Name
'// Fill the buffer with the maximum length (255 characters)
sResult = Space(255)
'// Call the API function
Call apiGetComputerName(sResult, 255)
'// Get the returned value, stripping off any trailing
null characters
'// lPos contains the length of the computer name
GetPCName =StripTerminator(sResult)
End Sub
Private Function StripTerminator(sString As String) As String
StripTerminator = Left$(sString, InStr(sString, Chr$(0))
- 1)
End Function