sxingfeng
sxingfeng

Reputation: 1087

How to know whether I have admin authority in windows?

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

BOOL IsHasAuthority() { }

Many Thanks!

Upvotes: 2

Views: 258

Answers (2)

anno
anno

Reputation: 5989

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.

Upvotes: 2

James McNellis
James McNellis

Reputation: 355079

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.

Upvotes: 1

Related Questions