Getting the User Name in Access

B

BBM

How does one get the User Name of the User signed onto the
local machine in Windows XP? Is there a function for this?

Does this change for a user logged into a Windows Server
Domain?

Thanks.

BBM
 
B

Bogdan Zamfir

Hi,
How does one get the User Name of the User signed onto the
local machine in Windows XP? Is there a function for this?

Does this change for a user logged into a Windows Server
Domain?

Don't think so, since it is retrieved through Windows API

Use the following code:

Private Declare Function WNetGetUser Lib "Mpr" Alias "WNetGetUserA" _
(lpName As Any, ByVal lpUserName As String, lpnLength As Long) As Long

Function GetUserName() As String
Dim UserName As String, cbusername, ret As Long

UserName = Space(256)
cbusername = Len(UserName)
ret = WNetGetUser(ByVal 0&, UserName, cbusername)
If ret = 0 Then
' Success - strip off the null.
UserName = VBA.Left(UserName, InStr(UserName, Chr(0)) - 1)
Else
UserName = ""
End If
GetUserName = UserName
End Function

HTH,
Bogdan Zamfir
_________________________

Independent consultant
 
G

Guest

Thanks. I'll give this a try.
BBM
-----Original Message-----
Hi,


Don't think so, since it is retrieved through Windows API

Use the following code:

Private Declare Function WNetGetUser Lib "Mpr" Alias "WNetGetUserA" _
(lpName As Any, ByVal lpUserName As String, lpnLength As Long) As Long

Function GetUserName() As String
Dim UserName As String, cbusername, ret As Long

UserName = Space(256)
cbusername = Len(UserName)
ret = WNetGetUser(ByVal 0&, UserName, cbusername)
If ret = 0 Then
' Success - strip off the null.
UserName = VBA.Left(UserName, InStr(UserName, Chr (0)) - 1)
Else
UserName = ""
End If
GetUserName = UserName
End Function

HTH,
Bogdan Zamfir
_________________________

Independent consultant




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top