1
我需要測試指定帳戶的組成員資格。python:如何枚舉本地Windows組成員身份
定帳戶 'X',是組 'A' 和 'B'
的成員,這是本地Windows帳戶2003年的服務器,而不是一個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"
是的,這也是我使用的 – Fabio 2016-07-11 15:16:45