Sign in with
Sign up | Sign in
Your question

How to obtain the username/ login on Server from Access Ap..

Last response: in Windows 2000/NT
Share
July 23, 2004 1:28:03 PM

Archived from groups: microsoft.public.win2000.advanced_server (More info?)

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
Anonymous
July 23, 2004 7:31:00 PM

Archived from groups: microsoft.public.win2000.advanced_server (More info?)

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" <a@discussions.microsoft.com.> wrote in message
news:B362AC46-1325-4895-90B1-46E177DB68A4@microsoft.com...
> 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
>
July 23, 2004 7:36:34 PM

Archived from groups: microsoft.public.win2000.advanced_server (More info?)

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).
>
>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
>
>.
>
Related resources
July 28, 2004 6:02:05 AM

Archived from groups: microsoft.public.win2000.advanced_server (More info?)

I would like to try it but I don't know how to access to system variables ? Have you any sample code VB ?

--
Anna


"Johnathan" wrote:
>
> 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).
> >
> >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
> >
> >.
> >
>
July 28, 2004 6:14:01 AM

Archived from groups: microsoft.public.win2000.advanced_server (More info?)

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

"Joe Pegram" wrote:

> 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" <a@discussions.microsoft.com.> wrote in message
> news:B362AC46-1325-4895-90B1-46E177DB68A4@microsoft.com...
> > 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
> >
>
>
>
!