Home All Groups Group Topic Archive Search About

Knowing which user logged on

Author
27 Nov 2007 3:08 PM
Joe Saliba
is it possible to know which user and which groupe he belongs who's
logged on a domain thru active directory ??? thank u for ur help.

*** Sent via Developersdex http://www.developersdex.com ***

Author
27 Nov 2007 9:57 PM
Karl E. Peterson
Joe Saliba wrote:
> is it possible to know which user and which groupe he belongs who's
> logged on a domain thru active directory ??? thank u for ur help.

Of course.
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
28 Nov 2007 1:12 PM
Rick Raisley
I use the following code to determine the user (don't know about the
domain):

   Do
      a$ = Environ(FF%)
      If UCase$(Left(a$, 9)) = "USERNAME=" Then
         MsgBox a$
         Exit Do
      End If
   Loop Until a$ = ""

--
Regards,

Rick Raisley

Show quote
"Joe Saliba" <joseph***@hotmail.com> wrote in message
news:u1VQZdQMIHA.4272@TK2MSFTNGP05.phx.gbl...
>
>
> is it possible to know which user and which groupe he belongs who's
> logged on a domain thru active directory ??? thank u for ur help.
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
28 Nov 2007 4:14 PM
Rick Raisley
Sorry, in simplifying my actual code, I went a bit too far. Here's the
corrected version:

   FF% = 1   ' Initialize index to 1.
   Do
      a$ = Environ(FF%)
      If UCase$(Left(a$, 9)) = "USERNAME=" Then   ' Check PATH entry.
         Msgbox a$            Case "RRAISLEY":  CanRelease% = True
         Exit Do
      End If
      FF% = FF% + 1
   Loop Until a$ = ""


--
Regards,

Rick Raisley

Show quote
"Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-net> wrote in message
news:OdC0OCcMIHA.5208@TK2MSFTNGP04.phx.gbl...
> I use the following code to determine the user (don't know about the
> domain):
>
>    Do
>       a$ = Environ(FF%)
>       If UCase$(Left(a$, 9)) = "USERNAME=" Then
>          MsgBox a$
>          Exit Do
>       End If
>    Loop Until a$ = ""
>
> --
> Regards,
>
> Rick Raisley
>
> "Joe Saliba" <joseph***@hotmail.com> wrote in message
> news:u1VQZdQMIHA.4272@TK2MSFTNGP05.phx.gbl...
> >
> >
> > is it possible to know which user and which groupe he belongs who's
> > logged on a domain thru active directory ??? thank u for ur help.
> >
> > *** Sent via Developersdex http://www.developersdex.com ***
>
>
Author
28 Nov 2007 4:26 PM
Bob Butler
Show quote
"Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-net> wrote in message
news:OIOVQndMIHA.5400@TK2MSFTNGP04.phx.gbl...
> Sorry, in simplifying my actual code, I went a bit too far. Here's the
> corrected version:
>
>   FF% = 1   ' Initialize index to 1.
>   Do
>      a$ = Environ(FF%)
>      If UCase$(Left(a$, 9)) = "USERNAME=" Then   ' Check PATH entry.
>         Msgbox a$            Case "RRAISLEY":  CanRelease% = True
>         Exit Do
>      End If
>      FF% = FF% + 1
>   Loop Until a$ = ""

Apart from having a 'Case' keyword in the middle of nowhere that all reduces
to:

a$=environ$("USERNAME")

Which is an unreliable way to get the username since the environment
variable can be tampered with easily.  Try the GetUserNameEx API function.

Private Declare Function GetUserNameEx Lib "secur32" _
  Alias "GetUserNameExA" (ByVal format As Long, ByVal Name As String, _
  ByRef namlen As Long) As Long
Private Const NameUnknown As Long = 0
Private Const NameFullyQualifiedDN As Long = 1
Private Const NameSamCompatible As Long = 2
Private Const NameDisplay As Long = 3
Private Const NameEMail1 As Long = 4
Private Const NameEMail2 As Long = 5
Private Const NameUniqueId As Long = 6
Private Const NameCanonical As Long = 7
Private Const NameUserPrincipal As Long = 8
Private Const NameCanonicalEx As Long = 9
Private Const NameServicePrincipal As Long = 10
Private Const NameDnsDomain As Long = 12

Public Function CurrentUser(Optional ByVal NameType As Long =
NameSamCompatible) As String
Dim sBuff As String * 512
Dim x As Long
x = GetUserNameEx(NameSamCompatible, sBuff, Len(sBuff) - 1)
If x > 0 Then
  x = InStr(sBuff, vbNullChar)
  If x > 0 Then CurrentUser = Left$(sBuff, x - 1)
End If
End Function
Author
29 Nov 2007 1:23 PM
Rick Raisley
Sorry about the errant Case, but thanks for letting me know you can include
the variable in the "array". The examples I'd seen didn't do it that way,
but just went through them all to find what they needed. Of course, while
many are used on all systems, others are specific, so when looking for them
all, it makes sense to do it that way.

Anyhow, thanks for the info; I can use that. ;-)

--
Regards,

Rick Raisley

Show quote
"Bob Butler" <noway@nospam.ever> wrote in message
>
> Apart from having a 'Case' keyword in the middle of nowhere that all
reduces
> to:
>
> a$=environ$("USERNAME")
>
> Which is an unreliable way to get the username since the environment
> variable can be tampered with easily.  Try the GetUserNameEx API function.
>
> Private Declare Function GetUserNameEx Lib "secur32" _
>   Alias "GetUserNameExA" (ByVal format As Long, ByVal Name As String, _
>   ByRef namlen As Long) As Long
> Private Const NameUnknown As Long = 0
> Private Const NameFullyQualifiedDN As Long = 1
> Private Const NameSamCompatible As Long = 2
> Private Const NameDisplay As Long = 3
> Private Const NameEMail1 As Long = 4
> Private Const NameEMail2 As Long = 5
> Private Const NameUniqueId As Long = 6
> Private Const NameCanonical As Long = 7
> Private Const NameUserPrincipal As Long = 8
> Private Const NameCanonicalEx As Long = 9
> Private Const NameServicePrincipal As Long = 10
> Private Const NameDnsDomain As Long = 12
>
> Public Function CurrentUser(Optional ByVal NameType As Long =
> NameSamCompatible) As String
> Dim sBuff As String * 512
> Dim x As Long
> x = GetUserNameEx(NameSamCompatible, sBuff, Len(sBuff) - 1)
> If x > 0 Then
>   x = InStr(sBuff, vbNullChar)
>   If x > 0 Then CurrentUser = Left$(sBuff, x - 1)
> End If
> End Function
>
>
Author
29 Nov 2007 5:18 PM
Rick Raisley
I see that the USERDOMAIN environment variable is also available. Not sure
if that is the GROUP that the original poster asked about or not.

--
Regards,

Rick Raisley

Show quote
"Bob Butler" <noway@nospam.ever> wrote in message
news:eZjKvudMIHA.4948@TK2MSFTNGP02.phx.gbl...
> "Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-net> wrote in message
> news:OIOVQndMIHA.5400@TK2MSFTNGP04.phx.gbl...
> > Sorry, in simplifying my actual code, I went a bit too far. Here's the
> > corrected version:
> >
> >   FF% = 1   ' Initialize index to 1.
> >   Do
> >      a$ = Environ(FF%)
> >      If UCase$(Left(a$, 9)) = "USERNAME=" Then   ' Check PATH entry.
> >         Msgbox a$            Case "RRAISLEY":  CanRelease% = True
> >         Exit Do
> >      End If
> >      FF% = FF% + 1
> >   Loop Until a$ = ""
>
> Apart from having a 'Case' keyword in the middle of nowhere that all
reduces
> to:
>
> a$=environ$("USERNAME")
>
> Which is an unreliable way to get the username since the environment
> variable can be tampered with easily.  Try the GetUserNameEx API function.
>
> Private Declare Function GetUserNameEx Lib "secur32" _
>   Alias "GetUserNameExA" (ByVal format As Long, ByVal Name As String, _
>   ByRef namlen As Long) As Long
> Private Const NameUnknown As Long = 0
> Private Const NameFullyQualifiedDN As Long = 1
> Private Const NameSamCompatible As Long = 2
> Private Const NameDisplay As Long = 3
> Private Const NameEMail1 As Long = 4
> Private Const NameEMail2 As Long = 5
> Private Const NameUniqueId As Long = 6
> Private Const NameCanonical As Long = 7
> Private Const NameUserPrincipal As Long = 8
> Private Const NameCanonicalEx As Long = 9
> Private Const NameServicePrincipal As Long = 10
> Private Const NameDnsDomain As Long = 12
>
> Public Function CurrentUser(Optional ByVal NameType As Long =
> NameSamCompatible) As String
> Dim sBuff As String * 512
> Dim x As Long
> x = GetUserNameEx(NameSamCompatible, sBuff, Len(sBuff) - 1)
> If x > 0 Then
>   x = InStr(sBuff, vbNullChar)
>   If x > 0 Then CurrentUser = Left$(sBuff, x - 1)
> End If
> End Function
>
>
Author
29 Nov 2007 5:28 PM
Bob Butler
"Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-net> wrote in message
news:%23dA1lxqMIHA.4308@TK2MSFTNGP05.phx.gbl...
>I see that the USERDOMAIN environment variable is also available. Not sure
> if that is the GROUP that the original poster asked about or not.

GetUserNameEx returns the domain as well; I wasn't sure what was meant by
the group so can't answer that unless the OP elaborates

AddThis Social Bookmark Button