Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Detection of administrator? Posted by Sephiroth on 17 Jan 2009 at 12:25 PM
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?

-Sephiroth
Report
Re: Detection of administrator? Posted by carly on 18 Jan 2009 at 8:48 AM
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...)
Report
Re: Detection of administrator? Posted by Sephiroth on 19 Jan 2009 at 5:25 PM
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.

-Sephiroth
Report
Re: Detection of administrator? Posted by carly on 23 Jan 2009 at 11:32 AM
- You don't need any News Readers. Usenet archives are on Google Groups
- *** All answers *** are on Usenet for 20 years
- 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

Report
Re: Detection of administrator? Posted by Sephiroth on 11 Feb 2009 at 10:51 PM
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;
  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;

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.

-Sephiroth



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.