python:如何枚举本地Windows组成员身份

发布于 2024-11-08 01:54:25 字数 880 浏览 1 评论 0原文

我需要测试指定帐户的组成员身份。

给定帐户“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住我的手 2024-11-15 01:54:25

您需要使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文