views:

61

answers:

2

Is there any APIs in windows to detect whether the current user(current now) has the admin authority?

BOOL IsHasAuthority() { }

Many Thanks!

+1  A: 

You can use the Windows API function CheckTokenMembership(). The MSDN documentation for that function has an example demonstrating how to check for membership in the Administrators local group.

James McNellis
The docs for [IsUserAnAdmin()](http://msdn.microsoft.com/en-us/library/bb776463.aspx) redirect to that page as well.
MSalters
@MSalters: Oh... I didn't know there was such a function. Cool.
James McNellis
+2  A: 

How to Determine Whether a Process or Thread Is Running As an Administrator

Use this solution when you are writing an application that must determine whether any of the following is true:

  • The current user can perform administrative tasks. The current
    user is a member of the
  • Administrators group. A supplied token handle represents an
    administrator with an elevated token.
  • A token handle represents a user who is a member of the Administrators group.
  • The program is running with an elevated token or needs to spawn a
    child program that is elevated so it
    can perform administrative tasks.
anno