PDA

Click to See Complete Forum and Search --> : User Connected


Nathan
Sep 19th, 2000, 11:41 AM
I need to know the name of the user or the group that the current connection is connected with. I am using NT security and a SQL Server database for the connection. Is there anyway to get this information?

If this isn't clear let me know and I'll try to explain better...

Sep 19th, 2000, 12:57 PM
i hope you mean the logon Name from Windows NT

Declare Function WNetGetUser Lib "mpr" Alias "WNetGetUserA" (ByVal lpName As String, ByVal LpUserName As String, LpnLength As Long) As Long

Function Get_NT_UserName() As String

Dim RetVal As Long, NamePuffer As String,Namen As String

NamePuffer = Space(255)
RetVal = WNetGetUser(vbNullString, NamePuffer, Len(NamePuffer))
Namen= Trim(NamePuffer)

If InStr(1, namen, Chr$(0)) > 0 Then
Namen = Left(Namen, Len(Namen)- 1)
Else
Namen = ""
End If

Get_NT_UserName = Namen

End Function

RIVES
Sep 19th, 2000, 01:04 PM
check out the sysprocesses table from the master database.

RIVES
Sep 19th, 2000, 01:15 PM
To be more specific, here's a SQL example

* You should have access to the master database.

USE MASTER
select hostname, program_name, nt_domain, nt_username, loginame from sysprocesses where dbid = db_id('northwind')

select spid, hostname, program_name, nt_domain, nt_username, loginame from sysprocesses where spid = user_id(current_user)

Hope this helps

[Edited by RIVES on 09-19-2000 at 02:19 PM]

Nathan
Sep 19th, 2000, 01:35 PM
thanx both of you...

Rives,
I don't have access to the sysprocesses table

maexchen,
I know how to get the name they used to log onto the machine, do you know how to get the names of any groups that they belong to?