Detection of administrator?

SephirothSephiroth Fayetteville, NC, USA
I am writing a backup utility that needs to know if a user is an admin. If so, the utility will have the option to backup an entire drive, other user folders and settings, and more. If not, these options won't be available since a normal user cannot access other user's folders and such. I am doing the application in C++. How can I determine whether or not a user is an admin when he or she starts the program?



  • It's a Win32 FAQ
    See on Adv. Win32 api newsgroup :
    (several well-known methods, SH and KL...)
  • SephirothSephiroth Fayetteville, NC, USA
    I don't have a news reader and I won't use Outlook Express. Not only that, but others can't benefit from the response. I'm not trying to be rude, but I'd like the post and information to be retained here for future programmers to see and use, and again I do not have a news reader and do not care to clutter my system up with something I'll use for five minutes to figure this out.

  • - You don't need any News Readers. Usenet archives are on Google Groups
    - *** All answers *** are on Usenet for [b]20 years [/b]
    - This question, like others ones, has been answered more than 250 times for 20 years all over the world
    - All answers are found on Usenet in less than 5 seconds.
    - All professional consultants use Usenet (on Windows : Win32 gurus, best-sellers authors, etc)
    - All professional consultants use News Readers, like Thunderbird, Outlook, Windows Mail, etc
    Windows Mail :

  • SephirothSephiroth Fayetteville, NC, USA
    I wanted to post the solution to this problem so that it would be here at PH for others to see. I found it after spending time looking up security functions and testing things on my own.
    BOOL bAdmin;
    PSID pSecurity;

    //Check for administrator rights
    if(AllocateAndInitializeSid(&siaLevel, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSecurity) != 0)
    CheckTokenMembership(NULL, pSecurity, &bAdmin);

    //We have to do this since MS won't use a real boolean
    this->bAdministrator = true;
    return false;
    Hope this helps somebody else.


    I wanted to point out that this code is inside a class method that returns a boolean (bool) type. That's why there is a "return false" statement if allocation fails.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!