Link to home
Start Free TrialLog in
Avatar of Mohammad Alsolaiman
Mohammad AlsolaimanFlag for Saudi Arabia

asked on

get user name "advapi32.dll" updated for use on 64-bit systems

Hi:
'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
'***************** Code Tested By Mohammed alsolaiman ***************
'I my self test this function, it works good.

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

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngx As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngx = apiGetUserName(strUserName, lngLen)
    If (lngx > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function
'******************** Code End **************************



Public Sub GetNetUserNane()
   MsgBox (fOSUserName)
End Sub

Open in new window

I've been using this code several years ago since access 2003 up till now.
But some times I encounter this error ( and I think when I use my apps. with  64-bit operating system )
Is there any alternative code for 64-bit. If so!, can I make it multi use. When 32-bit use this one, and when 64-bit use the new one!.
Please help.

User generated image
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mohammad Alsolaiman

ASKER

thanks a lot, and sorry for late