GetUserName



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

Sub Get_User_Name()
Dim lpBuff As String * 25
Dim ret As Long

'Get the user name minus any trailing

'spaces found in the name.


ret = resName(lpBuff, 25)
UserName = UCase(Left(lpBuff, InStr(lpBuff, Chr(0)) - 1))
'Gets the length of the name

strLen = Len(UserName)
'takes 2 away from that length

nLen = strLen - 2
'Gets the first letter of the name - makes uppercase

fLets = UCase(Left(UserName, 1))
'Gets the second letter of the name - makes uppercase

sLets = UCase(Mid(UserName, 2, 1))
'Gets the rest of the name thats left - makes Lowercase

rLets = LCase(Mid(UserName, 3, nLen))
'Puts it all together (ie: P.Smith)

strUser = fLets & "." & sLets & rLets
End Sub

(getusername.html)- by Paolo Puglisi - Modifica del 25/3/2019