我需要测试指定帐户的群组成员资格。
鉴于帐户'X',它是组'A'和'B'的成员
这些是2003服务器上的本地Windows帐户,而不是DC,并且它不连接到DC。
这是我在指向正确方向后形成的答案
import win32net
import platform
import getpass
#Get current hostname and username
sHostname = platform.uname()[1]
sUsername = getpass.getuser()
#Define account memberships to test as false
memberAdmin = False
memberORA_DBA = False
for groups in win32net.NetUserGetLocalGroups(sHostname,sUsername):
#If membership present, set to true
if groups == 'Administrators':
print "member of admin"
memberAdmin = True
if groups == 'ORA_DBA':
print "member of ORA_DBA"
memberORA_DBA = True
#if all true pass, else fail
if (memberAdmin == True) and (memberORA_DBA == True):
print "membership is good"
else:
print "current account does not have the proper group membership"