Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Windows Administrator account check

Windows Administrator account check

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lord_Draconis
    wrote on last edited by
    #1

    Hello, Is there a decent way to check if the user currently logged in is the Administrator?? Thanks Draco

    M N D 3 Replies Last reply
    0
    • L Lord_Draconis

      Hello, Is there a decent way to check if the user currently logged in is the Administrator?? Thanks Draco

      M Offline
      M Offline
      Martin Ziacek
      wrote on last edited by
      #2

      do you mean something like this: LONG WINAPI IsUserAdmin(void) { BOOL b; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; PSID AdministratorsGroup; b = AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); if(b) { if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) { b = FALSE; } FreeSid(AdministratorsGroup); } return(b); }

      Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

      P 1 Reply Last reply
      0
      • M Martin Ziacek

        do you mean something like this: LONG WINAPI IsUserAdmin(void) { BOOL b; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; PSID AdministratorsGroup; b = AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); if(b) { if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) { b = FALSE; } FreeSid(AdministratorsGroup); } return(b); }

        Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

        P Offline
        P Offline
        Peter Weyzen
        wrote on last edited by
        #3

        I am so shocked that anyone understands the security stuff in windows!

        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)

        M 1 Reply Last reply
        0
        • P Peter Weyzen

          I am so shocked that anyone understands the security stuff in windows!

          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)

          M Offline
          M Offline
          Martin Ziacek
          wrote on last edited by
          #4

          :) LOL, it is not that difficult, you just need to spend a lot of time reading and experimenting.

          Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

          P 1 Reply Last reply
          0
          • M Martin Ziacek

            :) LOL, it is not that difficult, you just need to spend a lot of time reading and experimenting.

            Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

            P Offline
            P Offline
            Peter Weyzen
            wrote on last edited by
            #5

            The best thing about windows security -- is that you don't have to understand it. All those functions that want a SECURITY_ATTRIBUTES pointer happily accept a NULL pointer!

            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)

            M N 2 Replies Last reply
            0
            • P Peter Weyzen

              The best thing about windows security -- is that you don't have to understand it. All those functions that want a SECURITY_ATTRIBUTES pointer happily accept a NULL pointer!

              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)

              M Offline
              M Offline
              Martin Ziacek
              wrote on last edited by
              #6

              and still it works, using NULL indicates that default attributes for the process will be used hence the job is done for you. if you need a different attributes then you can set them up, used to be pretty dull and long code but it is getting better. get hold of books 'Writing Secure Code' and 'Writing Secure Code for Windows Vista', that's good start.

              Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

              1 Reply Last reply
              0
              • P Peter Weyzen

                The best thing about windows security -- is that you don't have to understand it. All those functions that want a SECURITY_ATTRIBUTES pointer happily accept a NULL pointer!

                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #7

                :omg::omg::doh::doh: Everyday I think more and more to move on linux ;P :rolleyes:

                Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)

                1 Reply Last reply
                0
                • L Lord_Draconis

                  Hello, Is there a decent way to check if the user currently logged in is the Administrator?? Thanks Draco

                  N Offline
                  N Offline
                  Nibu babu thomas
                  wrote on last edited by
                  #8

                  Lord_Draconis wrote:

                  Is there a decent way to check if the user currently logged in is the Administrator??

                  Use IsUserAnAdmin.


                  Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http:\\nibuthomas.wordpress.com

                  1 Reply Last reply
                  0
                  • L Lord_Draconis

                    Hello, Is there a decent way to check if the user currently logged in is the Administrator?? Thanks Draco

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Lord_Draconis wrote:

                    Is there a decent way to check if the user currently logged in is the Administrator??

                    char szName[64];
                    GetUserName(szName, sizeof(szName));
                    strcmp(szName, "Administrator");

                    I'm not sure how useful this is going to be, however. I would think you'd want to know if the currently logged on user was a member of the Administrator group or not.


                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    M 1 Reply Last reply
                    0
                    • D David Crow

                      Lord_Draconis wrote:

                      Is there a decent way to check if the user currently logged in is the Administrator??

                      char szName[64];
                      GetUserName(szName, sizeof(szName));
                      strcmp(szName, "Administrator");

                      I'm not sure how useful this is going to be, however. I would think you'd want to know if the currently logged on user was a member of the Administrator group or not.


                      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      :-D

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups