Get users network login name when different from the windows local login name

Get users network login name when different from the windows local login name

Post by Ian Burto » Sun, 03 Aug 2003 00:11:36


Hi everyone,
I want to get the users login name, and currently use a number of functions,
one of which is based on this one:
http://www.yqcomputer.com/

However, it doesn't work properly on a network. If the user logs into the
network as joe, and then in the local windows PC as Administrator, then that
function will bring back Administrator.

I have functionality in some applications that is only available to the
network admin, but if a user can use a local user account on their own
machine called admin, then that function will think they are the network
administrator.

I have seen a bunch of different functions, including one below, which I
kindly found from a web site earlier today:
this doesn't do it either. Perhaps in a mostly windows environment, it does
not get this kind of use, but it doesn't work with for example a netware and
windows network. Does it even work with a domain login where local login is
different? What about if a user logs into a few networks at once with
different network adaptors? How can I find out a particular user name for a
particular network name?

I would really like to get this sorted once and for all, and thought this
might be the place. thanks for your help.

''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''
''''get network user name function apinetusername function - doesn't work
properly
'source thread:
http://www.yqcomputer.com/ %40barneyboller.com&rnum=1&prev=/groups%3Fselm%3D387490BE.1CD2C4D3%2540barneyboller.com
Public Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long
Const NoError = 0 'The Function call was successful
Public Function FindNetUserName() As String

' Buffer size for the return string.
Const lpnLength As Integer = 255
' Get return buffer space.
Dim status As Integer
' For getting user information.
Dim lpName, lpUserName As String
' Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)
' Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)
' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings in C are null-
' terminated. Strings in Visual Basic are not null-terminated.
' The null character must be removed from the C strings to be
used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
Else
' An error occurred.
lpUserName = ""
End
End If
FindNetUserName = lpUserName
End Function
 
 
 

Get users network login name when different from the windows local login name

Post by Ian Burto » Tue, 05 Aug 2003 20:53:28

"Dimitri Furman" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...

Dmitri,
that is great, and does it perfectly. In a situation such as I describe
where a user is logging onto netware as Joe, and the local machine in
windows2000 as Administrator, this one returns Joe. thanks.
Do you know how to find out what the tree name is? and then also, I guess I
need to find a function to find the windows domain name, and user name and
then depending on which network exists, call one of the two functions.
If you don't know, I will see if I can find that particular code, and post
it here when i have it.
thanks for your answer,
Ian.



 
 
 

Get users network login name when different from the windows local login name

Post by Dimitri Fu » Wed, 06 Aug 2003 10:21:25

On Aug 04 2003, 12:05 pm, "Ian Burton" < XXXX@XXXXX.COM > wrote in



It doesn't require that you know the name of a resource on the network
(which doesn't have to be the tree name, could be a server, a printer,
etc.), but IIRC, it does require the Netware Client to be installed.
WNetGetUserA is a Windows function and should work with any network.

There are uses for both methods.

--
(remove a 9 to reply by email)