2

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

BOOL IsHasAuthority() { }

Many Thanks!

sxingfeng
  • 971
  • 4
  • 15
  • 32

2 Answers2

2

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
  • 5,970
  • 4
  • 28
  • 37
1

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
  • 348,265
  • 75
  • 913
  • 977