Get NT Userid

prao

Registered User.
Local time
Today, 14:46
Joined
Apr 16, 2001
Messages
32
Hi All

How to get NT Userid and Password inside Access.

Thanks
 
Create a module and paste in this code to get the current userid then put a text box on your form.

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)
ElsefOSUserName = ""
End If
End Function

Hay
 
Hi Hay

Thanks for the reply. I have a question for you. Where do I need to use these lines of script from your program.

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

Thanks
 
sample

Click on my profile to send me an email so I can get your email address and I'll send you a sample of this(I don't know if attachments can be sent via email using this forum)

Hay
 
Hi Hay

Thank you very much for the reply. It is working fine.
 
Has anybody got a working version for Access 2? I know, I have an oldie that needs some fixing but I need to know who (NT ID) is using this old db.

This is what I am using but it is bugging on the bolded line and the message is "Error in loading DLL."

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

Function fOSUserName () As String
'On Error Resume Next

'Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = GetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
ElsefOSUserName = ""
End If

End Function

Thanks in advance for your help!
 
Found it @
http://easyweb.easynet.co.uk/~trevor/AccFAQ/

This will work for Access 2.0

Declare Function WNetGetUser Lib "user" (ByVal szUser As String, nBufferSize As Integer) As Integer
Function NetworkUserName () As String

Dim iStringLength As Integer
Dim sString As String * 255

iStringLength = Len(sString)
sString = String$(iStringLength, 0)

If WNetGetUser(sString, iStringLength) = 0 Then
NetworkUserName = Left$(sString, iStringLength)
Else
NetworkUserName = "Unknown"
End If

End Function
 

Users who are viewing this thread

Back
Top Bottom