Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Detection of administrator?

SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
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?

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • carlycarly Posts: 46Member
    It's a Win32 FAQ
    See on Adv. Win32 api newsgroup :
    news://comp.os.ms-windows.programmer.win32
    (several well-known methods, SH and KL...)
  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    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.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
  • carlycarly Posts: 46Member
    - 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 :
    http://support.cox.com/sdccommon/asp/contentredirect.asp?sprt_cid=285b1ded-6ed2-42d9-ac7b-9ad40513af96

  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    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.
    [code]
    BOOL bAdmin;
    PSID pSecurity;
    SID_IDENTIFIER_AUTHORITY siaLevel = SECURITY_NT_AUTHORITY;

    //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);
    FreeSid(pSecurity);

    //We have to do this since MS won't use a real boolean
    if(bAdmin)
    this->bAdministrator = true;
    }
    else
    return false;
    [/code]
    Hope this helps somebody else.

    *EDIT*

    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.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
Sign In or Register to comment.