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
Returns:
Usersname in a more pleasant format

'Assumes:

Paste in the Declaration, and then put the code
into a module, then from your form, call the
function 'Get_User_Name' then create a control
which will return the value and ref that control
after calling the function, ie: label1.caption = strUser












( getusername.html )- by Paolo Puglisi - Modifica del 17/12/2023