当用户位于管理员组中时,ctypes.windll.shell32.IsUserAdmin() 不返回 1

发布于 2024-12-15 00:03:02 字数 599 浏览 7 评论 0原文

我尝试使用

ctypes.windll.shell32.IsUserAdmin()

来确定正在运行的进程是否是由 Admins 组中的用户启动的,但我得到的结果不一致/不正确。

在 Windows 7 Professional 安装中,当以不是管理员但属于管理员组成员的用户身份登录时,我得到

>>> ctypes.windll.shell32.IsUserAnAdmin()
0

But the user is in the admins group。

当我以管理员身份登录时,我在 Windows Server 2008 计算机上得到了预期的答案;

>>> ctypes.windll.shell32.IsUserAnAdmin()
1

有谁知道/有任何提示,为什么我在 win7 盒子上得到 0 返回,即使用户位于 administartors 组中?

  • 我想知道这个问题是否可能是由本地与域管理员/组之间的某些交互引起的,但我对此的了解充其量是粗略的。

谢谢,

马特。

I am trying to use

ctypes.windll.shell32.IsUserAdmin()

to determine if the running process was started by a user in the Admins group, but I am getting inconsistent / incorrect results.

On a windows 7 professional install, when logging in as a user that is not Administrator but is a memebr of the administrators group, I get

>>> ctypes.windll.shell32.IsUserAnAdmin()
0

But the user is in the admins group.

I get the expected answer on a windows server 2008 machine when logging in as Administrator;

>>> ctypes.windll.shell32.IsUserAnAdmin()
1

Does anybody know / have any hints as to why I am getting a 0 returned on the win7 box, even though the user is in the administartors group?

  • I am wondering if the issue can be caused by some interaction of local vs domain admins / groups, but my knowledge there is sketchy at best..

Thanks,

Matt.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

少钕鈤記 2024-12-22 00:03:02

这是UAC。如果你跑得更高,你就会看到你期望的行为。但是,使用 UAC 下的标准令牌,您的用户没有管理员权限,即使在管理员组中也是如此。

对于特殊的管理员用户帐户,UAC 不适用,并且该特殊用户下的进程始终会获得特权令牌。因此,您看到的差异不在于操作系统,而在于用户。以 Windows 7 上的特殊管理员帐户身份登录,您会发现它的行为与 server 2008 盒子一样。

This is UAC. If you run elevated, you will see the behaviour you expect. But with a standard token under UAC your user doesn't have administrator rights, even when in the admin group.

For the special Administrator user account, UAC does not apply and processes under that special user are always given a privileged token. So the difference you see is not with the OS but with the user. Log on as the special Administrator account on Windows 7 and see that it behaves just as the server 2008 box does.

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