How to obtain the username/ login on Server from Access Applicatio

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody,

I need to retrieve the name of user, logged on Windows Server from my MSAccess Application.

I've tried the "NetWkstaUserGetInfo" function, but it only returns the local machine username.

How to retrieve the network login name ?

The function "LsaGetLogonSessionData" seems to be helpful but I can't even accessed the description page on MSDN site (the page is not available).

May be there is another way to do that?

If anybody have a VB code using this or another function, thanks very much in advance,

Anna
 
I use this code with VB6:

Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal
lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long


Public Function CurUser() As String

Dim tmpVal As Long
Dim lpName As String
Dim lpUserName As String
Dim lpnLength As Long

On Error GoTo CurUser_ErrorHandler

lpName = ""
lpUserName = String(255, 0)
lpnLength = 255

tmpVal = WNetGetUser(lpName, lpUserName, lpnLength)
If tmpVal = 0 Then
'Got userid
tmpVal = InStr(lpUserName, Chr(0))
If tmpVal > 0 Then
'tmpval better be >0!
CurUser = Left(lpUserName, tmpVal - 1)
End If
End If

Exit Function

CurUser_ErrorHandler:

Exit Function

End Function



Anna said:
Hi everybody,

I need to retrieve the name of user, logged on Windows Server from my MSAccess Application.

I've tried the "NetWkstaUserGetInfo" function, but it only returns the local machine username.

How to retrieve the network login name ?

The function "LsaGetLogonSessionData" seems to be helpful but I can't even
accessed the description page on MSDN site (the page is not available).
 
You could also use the system variable %username%, this
will not work in Win95, Win98 - not sure about ME.
-----Original Message-----
Hi everybody,

I need to retrieve the name of user, logged on Windows
Server from my MSAccess Application.
I've tried the "NetWkstaUserGetInfo" function, but it
only returns the local machine username.
How to retrieve the network login name ?

The function "LsaGetLogonSessionData" seems to be helpful
but I can't even accessed the description page on MSDN
site (the page is not available).
 
Thank you for the code Joe. I've integrated it into my application and it works. But if I connect a new network reader ("Z" for exemple) to another network and then I try to pass a parameter lpname as "Z:" or even "C:" the function returns the error "ERROR_BAD_NETPATH". Do your have any idea why it happens ?

Anna
 

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

Back
Top