Share via

Difference between Environ function or API function to get the window session username

Anonymous
2014-12-10T09:17:37+00:00

Hello

I used previously this API function

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

Function GetUserName() As Variant

   Dim strUserName As String, lngLength As Long, lngResult As Long

   strUserName = String$(255, 0)

   lngLength = 255

   lngResult = wu_GetUserName(strUserName, lngLength)

   GetUserName = Left(strUserName, InStr(1, strUserName, Chr(0)) - 1)

End Function

Similarly, you could use : Environ("username")

Both function return the same string that needs to be the current user/window session logged on that pc.

Any comment ?

Regards

JY

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2014-12-10T18:53:54+00:00

    Hi Bernie

    C+/Dotnet can also use vba language (make a ref to that library), does not really help for my understanding....

    Thank you

    JY

    Was this answer helpful?

    0 comments No comments