How to get Windows Username ?

  • Thread starter Thread starter Rudi K.
  • Start date Start date
Option Compare Text
Option Explicit
Declare Function GetUserName Lib "advapi32.dll"
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As
Long) As Long

Public Function UserName() As String
'this gets the network user login
Dim lpBuff As String * 25
Dim Ret
Ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
End Function
 
It works !!!!!
Thanks NGAN......
-----Original Message-----
Option Compare Text
Option Explicit
Declare Function GetUserName Lib "advapi32.dll"
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As
Long) As Long

Public Function UserName() As String
'this gets the network user login
Dim lpBuff As String * 25
Dim Ret
Ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
End Function

.
 
Back
Top