Retrieve Username

There comes a time in almost every program when you want to know who is the currently logged in user… here’s a little function to do that…

Declare Function GetUserName Lib “advapi32.dll” Alias _
“GetUserNameA” (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer

Public Function retUserName() As String
Dim iReturn As Integer
Dim userName As String
userName = New String(CChar(” “), 50)
iReturn = GetUserName(userName, 50)
retUserName = userName.Substring(0, userName.IndexOf(Chr(0)))
End Function

2 thoughts on “Retrieve Username

  1. Would you have any idea on how to get my user name from I can’t remember user name to save my life. I have contacted wordpress several times and nothing. Do you no where they are located?

  2. Unfortunately i’m not sure where to find a lost wordpress username. If this is a free account, you could try searching google for known articles you’ve written. I can spot my writing, if it’s long enough, a mile away…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s