|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Knowing which user logged onis 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 *** Joe Saliba wrote:
> is it possible to know which user and which groupe he belongs who's Of course.> logged on a domain thru active directory ??? thank u for ur help. 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$ = "" -- Show quoteRegards, 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 *** 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$ = "" -- Show quoteRegards, Rick Raisley "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 *** > >
Show quote
"Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-net> wrote in message Apart from having a 'Case' keyword in the middle of nowhere that all reduces 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$ = "" 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 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. ;-) -- Show quoteRegards, Rick Raisley "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 > > 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. -- Show quoteRegards, Rick Raisley "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 > > "Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-net> wrote in message GetUserNameEx returns the domain as well; I wasn't sure what was meant by 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. the group so can't answer that unless the OP elaborates |
|||||||||||||||||||||||