python:如何枚举本地Windows组成员身份
我需要测试指定帐户的组成员身份。
给定帐户“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"
I need to test group membership of specified accounts.
Given Account 'X', is it a member of groups 'A' and 'B'
These are local windows accounts on a 2003 server, not a DC and it does not connect to a DC.
Here is the answer I formed after being pointed in the correct direction
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 Python Win32 扩展 与 Windows 交互。我认为 win32net 模块中的一些方法将帮助您获得您需要的信息。
You need to use Python Win32 Extensions to interact with Windows. I think some of the methods in win32net module would help you to get the information you need.