如何检查是否给定的用户是内置的管理员组的成员?

问题描述:

我需要检查编程方式(在.NET)给定用户(域帐户)是否是其成员的内置Administrators组中的当前计算机(一凡申请得到执行)。

I need to check programmatically (in .NET) whether a given user (domain account) is a member of the built-in Administrators group on a current computer (the one where the application gets executed).

这可能吗?

我不知道关于.NET,但在Win32中,最简单的方法是调用IsUserAnAdmin()。如果您需要更多的控制,你可以打开进程令牌,并检查与CheckTokenMembership每个需要检查组

I don't know about .Net, but in win32, the easy way is to call IsUserAnAdmin(). If you need more control, you can open the process token and check with CheckTokenMembership for each group you need to check

编辑:查看 pinvoke.net 对于.NET示例code(感谢chopeen)

See pinvoke.net for .NET sample code (Thanks chopeen)