[python-win32] Is this user a member of a given Active Directory group?
Tim Golden
mail at timgolden.me.uk
Tue Aug 5 11:55:59 CEST 2008
Vernon Cole wrote:
> Tim,
> You Da Man!
> Vernon
>
> based on your suggestion, I have:
> <code>
> import win32security
>
> def testMemberOf(GROUP_NAME):
> try:
> sid, system, type = win32security.LookupAccountName(None,
> GROUP_NAME)
> except:
> raise ValueError, '"%s" is not a valid group name'%GROUP_NAME
> return win32security.CheckTokenMembership(None, sid)
> </code>
Glad it helped. One thing -- which I imagine you
will have thought of for yourself, but just in
case... -- is that catching *all* exceptions might
mask something more than a misspelt group name.
But, clearly, the effect is the same: you can't
do the check against the group.
TJG
More information about the python-win32
mailing list