VB code -> Python
Jimmy Retzlaff
jimmy at retzlaff.com
Fri Feb 15 11:45:42 EST 2002
> Set oContext = GetObjectContext
> Err.Clear
> Set oUser = GetObject("WinNT://" & CStr(Domain) & "/" &
CStr(UserID))
> If Err = 0 Then
> For Each oGroup In oUser.Groups
> If UCase(Groupname) = UCase(oGroup.Name) Then
> MemberofGroup = True
> 'Exit Function
> Exit For
> End If
> Next
> oContext.SetComplete
> Else
> oContext.SetAbort
> MemberofGroup = False
> End If
>
>So my questin is how do I translate the GetObject(...) thing in to
>Python code.
Here is a version in Python, using your same variable names, etc.:
import win32com.client
def MemberofGroup(Domain, UserID, Groupname):
try:
oUser = win32com.client.GetObject(r'WinNT://%s/%s' % (Domain,
UserID))
except:
return 0
for oGroup in oUser.Groups():
if Groupname.upper() == oGroup.Name.upper():
return 1
print MemberofGroup(Domain='CoolDomain', UserID='Cool Guy',
Groupname='Domain Users')
Jimmy
More information about the Python-list
mailing list