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. How to get the user group in win NT/2000/XP

How to get the user group in win NT/2000/XP

Scheduled Pinned Locked Moved C / C++ / MFC
questionjsonhelptutorial
7 Posts 3 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.
  • C Offline
    C Offline
    C lviu
    wrote on last edited by
    #1

    I have a string specifying the user name in the format: "domain\username". My question is: How can I get the group to witch the user belongs to? I searched API's but couldn't find anything all I could find was "LookupAccountName" but it is not what I'm looking for. Please help if you know something. Thank's

    D B 2 Replies Last reply
    0
    • C C lviu

      I have a string specifying the user name in the format: "domain\username". My question is: How can I get the group to witch the user belongs to? I searched API's but couldn't find anything all I could find was "LookupAccountName" but it is not what I'm looking for. Please help if you know something. Thank's

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

      LookupAccountSid() is but one way. NetUserGetInfo() is another.


      A rich person is not the one who has the most, but the one that needs the least.

      C 1 Reply Last reply
      0
      • D David Crow

        LookupAccountSid() is but one way. NetUserGetInfo() is another.


        A rich person is not the one who has the most, but the one that needs the least.

        C Offline
        C Offline
        C lviu
        wrote on last edited by
        #3

        This is good, but it seems to work only for local users. It doesn't work for a user on a diffrent domain for exaple if my computer name is "Station" and it belongs to the "LAN" domain and there is a user on the domain "LAN" called "globalUser" and a user on the local machine called "localUser", the function fill fail if I try to look up the user "LAN\globalUser". Even more, NetUserEnum() will not show the user called "globalUser".

        D 1 Reply Last reply
        0
        • C C lviu

          This is good, but it seems to work only for local users. It doesn't work for a user on a diffrent domain for exaple if my computer name is "Station" and it belongs to the "LAN" domain and there is a user on the domain "LAN" called "globalUser" and a user on the local machine called "localUser", the function fill fail if I try to look up the user "LAN\globalUser". Even more, NetUserEnum() will not show the user called "globalUser".

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

          I can use the following to get all users on my PDC:

          LPUSER_INFO_0 pUserInfo = NULL,
          pUserInfoTemp = NULL;
          NET_API_STATUS nStatus;
          DWORD dwIndex,
          dwEntriesRead,
          dwTotalEntries,
          dwResumeHandle = 0;
          CString strText;

          nStatus = NetUserEnum(_T("\\\\tulsant"), 0, 0, (LPBYTE *) &pUserInfo, MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
          if (nStatus == NERR_Success || nStatus == ERROR_MORE_DATA)
          {
          pUserInfoTemp = pUserInfo;
          if (NULL != pUserInfoTemp)
          {
          for (dwIndex = 0; dwIndex < dwEntriesRead; dwIndex++)
          {
          if (NULL == pUserInfoTemp)
          break;

                  strText = pUserInfoTemp->usri0\_name;
                  m\_cbUserList.AddString(strText);
          
                  pUserInfoTemp++;
              }
          }
          

          }


          A rich person is not the one who has the most, but the one that needs the least.

          C 1 Reply Last reply
          0
          • D David Crow

            I can use the following to get all users on my PDC:

            LPUSER_INFO_0 pUserInfo = NULL,
            pUserInfoTemp = NULL;
            NET_API_STATUS nStatus;
            DWORD dwIndex,
            dwEntriesRead,
            dwTotalEntries,
            dwResumeHandle = 0;
            CString strText;

            nStatus = NetUserEnum(_T("\\\\tulsant"), 0, 0, (LPBYTE *) &pUserInfo, MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
            if (nStatus == NERR_Success || nStatus == ERROR_MORE_DATA)
            {
            pUserInfoTemp = pUserInfo;
            if (NULL != pUserInfoTemp)
            {
            for (dwIndex = 0; dwIndex < dwEntriesRead; dwIndex++)
            {
            if (NULL == pUserInfoTemp)
            break;

                    strText = pUserInfoTemp->usri0\_name;
                    m\_cbUserList.AddString(strText);
            
                    pUserInfoTemp++;
                }
            }
            

            }


            A rich person is not the one who has the most, but the one that needs the least.

            C Offline
            C Offline
            C lviu
            wrote on last edited by
            #5

            Yes, this works fine for local users but I want to list even the users on other domains. It must be possible beacause in Win2000 when I go to "Control Panel\Users and Passwords\Add\Browse" it shows me a list of all users on my domain but NetUserEnum() only enumerates the users that are stored on my computer.

            D 1 Reply Last reply
            0
            • C C lviu

              Yes, this works fine for local users but I want to list even the users on other domains. It must be possible beacause in Win2000 when I go to "Control Panel\Users and Passwords\Add\Browse" it shows me a list of all users on my domain but NetUserEnum() only enumerates the users that are stored on my computer.

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

              The code snippet I provided is for iterating the userlist on the listed domain controller. If it is not working for you, something else is at play. How are you using the NetUserEnum() function?


              A rich person is not the one who has the most, but the one that needs the least.

              1 Reply Last reply
              0
              • C C lviu

                I have a string specifying the user name in the format: "domain\username". My question is: How can I get the group to witch the user belongs to? I searched API's but couldn't find anything all I could find was "LookupAccountName" but it is not what I'm looking for. Please help if you know something. Thank's

                B Offline
                B Offline
                Brian Shifrin
                wrote on last edited by
                #7

                NetUserGetGroups or IADsUser::Groups

                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