VC judge the current user has no administrator permissions (with the Equalsid API function to determine whether the admin in a group SID)

Source: Internet
Author: User


[CPP]
View PlainCopyprint?
  1. /************************************************************************/
  2. /* Function Description: Determine whether there are administrator permissions
  3. /* Parameter: None
  4. /* Return value: True is returned successfully, otherwise false is returned
  5. /* By:koma 2009.07.28 23:30
  6. /************************************************************************/
  7. BOOL ISAdmin ()
  8. {
  9. HANDLE Haccesstoken;
  10. BYTE * InfoBuffer = new byte[1024];
  11. Ptoken_groups ptggroups;
  12. DWORD dwinfobuffersize;
  13. PSID psidadministrators;
  14. Sid_identifier_authority siantauthority = security_nt_authority;
  15. if (! OpenProcessToken (GetCurrentProcess (), Token_query,&haccesstoken))
  16. {
  17. Delete InfoBuffer;
  18. return FALSE;
  19. }
  20. if (! GetTokenInformation (haccesstoken,tokengroups,infobuffer,1024,&dwinfobuffersize))
  21. {
  22. Delete InfoBuffer;
  23. CloseHandle (Haccesstoken);
  24. return FALSE;
  25. }
  26. CloseHandle (Haccesstoken);
  27. if (! AllocateAndInitializeSid (&siantauthority,
  28. 2,
  29. Security_builtin_domain_rid,
  30. Domain_alias_rid_admins,
  31. 0,0,0,0,0,0,
  32. &psidadministrators))
  33. {
  34. Delete InfoBuffer;
  35. return FALSE;
  36. }
  37. Ptggroups = (ptoken_groups) InfoBuffer;
  38. For (UINT i = 0; i < ptggroups->groupcount; i++)
  39. {
  40. if (Equalsid (psidadministrators,ptggroups->groups[i). Sid))
  41. {
  42. Freesid (psidadministrators);
  43. Delete InfoBuffer;
  44. return TRUE;
  45. }
  46. }
  47. return FALSE;
  48. }

http://blog.csdn.net/wangningyu/article/details/4389546

VC judge the current user has no administrator permissions (with the Equalsid API function to determine whether the admin in a group SID)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.