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. Regarding NetUserAdd

Regarding NetUserAdd

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
12 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.
  • H Offline
    H Offline
    H4u32
    wrote on last edited by
    #1

    Hi all, I am creating Win32 application in which i need to create an account with administative privileges. I am able to create an account with normal user rights. But when i tried to create an account with administative privileges, it is giving error. So can't I create an account with admin rights directly?? Please help me out in this scenario. Any help would be greatly appreciated. Thanks Hemang

    R 1 Reply Last reply
    0
    • H H4u32

      Hi all, I am creating Win32 application in which i need to create an account with administative privileges. I am able to create an account with normal user rights. But when i tried to create an account with administative privileges, it is giving error. So can't I create an account with admin rights directly?? Please help me out in this scenario. Any help would be greatly appreciated. Thanks Hemang

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      Hemang Raval wrote:

      it is giving error.

      Don't you think that this is very vague? Are we supposed to guess the error? Please read and understand the guidelines[^] and keep your posts in accordance. Especially, look at the 2nd and 4th points.

      Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

      H 1 Reply Last reply
      0
      • R Rajesh R Subramanian

        Hemang Raval wrote:

        it is giving error.

        Don't you think that this is very vague? Are we supposed to guess the error? Please read and understand the guidelines[^] and keep your posts in accordance. Especially, look at the 2nd and 4th points.

        Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

        H Offline
        H Offline
        H4u32
        wrote on last edited by
        #3

        I apologize for such a vague post. I had tried to make it brief but was brief more than necessary. BTW i got solution for my previous vague post. My next problem is to change right of current user from administrator to limited user account . That is, i want to make current user from admin to limited account. I tried to do this with NetUserSetinfo(). But it is not working for my case. Hope for positive reply. Thanks, Hemang

        R 1 Reply Last reply
        0
        • H H4u32

          I apologize for such a vague post. I had tried to make it brief but was brief more than necessary. BTW i got solution for my previous vague post. My next problem is to change right of current user from administrator to limited user account . That is, i want to make current user from admin to limited account. I tried to do this with NetUserSetinfo(). But it is not working for my case. Hope for positive reply. Thanks, Hemang

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          Hemang Raval wrote:

          I tried to do this with NetUserSetinfo(). But it is not working for my case.

          You've done the same thing again. Why can't you tell us what exactly did you try and what does "not working" could possibly mean? The function failed? Did you check the return value to find out what went wrong? If not, why? The function succeeded, but did not give you expected results? Is your code perfect? Why don't you show the code? We cannot read your mind, you see. There's too less information in your post for anyone to give you any kind of helpful answer.

          Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

          H 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            Hemang Raval wrote:

            I tried to do this with NetUserSetinfo(). But it is not working for my case.

            You've done the same thing again. Why can't you tell us what exactly did you try and what does "not working" could possibly mean? The function failed? Did you check the return value to find out what went wrong? If not, why? The function succeeded, but did not give you expected results? Is your code perfect? Why don't you show the code? We cannot read your mind, you see. There's too less information in your post for anyone to give you any kind of helpful answer.

            Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

            H Offline
            H Offline
            H4u32
            wrote on last edited by
            #5

            I am sending the code snippet that i am using to change account type from admin to limited/noraml user. The user that i am trying to restrict has been created as admin. her is the code int getAdminNumber(int argc, wchar_t *argv[], LPWSTR user) { DWORD dwLevel = 2; LPUSER_INFO_0 pBuf = NULL; LPUSER_INFO_2 pBuf2 = NULL; NET_API_STATUS nStatus; LPTSTR sStringSid = NULL; wprintf(L"\nCalling NetUserGetinfo with Servername=%s Username=%s Level=%d\n", argv[1], user, dwLevel); nStatus = NetUserGetInfo(argv[1], user, dwLevel, (LPBYTE *) & pBuf); if (nStatus == NERR_Success) { if (pBuf != NULL) { pBuf2 = (LPUSER_INFO_2) pBuf; wprintf(L"\tUser account name: %s\n", pBuf2->usri2_name); wprintf(L"\tPrivilege level: %d\n", pBuf2->usri2_priv); if (pBuf2->usri2_priv == 2) cnt++; if(strcmp((char *)pBuf2->usri2_name, (char *)user) ==0) ChangeUserPrivilege(pBuf2->usri2_name, pBuf2->usri2_priv); } } else fprintf(stderr, "NetUserGetinfo failed with error: %d\n", nStatus); return 0; } void ChangeUserPrivilege(LPWSTR csUser, DWORD csPrivilege) { NET_API_STATUS nStatus; USER_INFO_1005 ui1005; DWORD dwLevel1005 = 1005; DWORD dwPrivilege; wchar_t *pswzUser = csUser; if(csPrivilege == 2) dwPrivilege = USER_PRIV_USER; ui1005.usri1005_priv = dwPrivilege; nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL); } I am not getting any error for above code but at the same time not getting desired output. Any help would be greatly appreciated. Thanks Hemang

            R D 2 Replies Last reply
            0
            • H H4u32

              I am sending the code snippet that i am using to change account type from admin to limited/noraml user. The user that i am trying to restrict has been created as admin. her is the code int getAdminNumber(int argc, wchar_t *argv[], LPWSTR user) { DWORD dwLevel = 2; LPUSER_INFO_0 pBuf = NULL; LPUSER_INFO_2 pBuf2 = NULL; NET_API_STATUS nStatus; LPTSTR sStringSid = NULL; wprintf(L"\nCalling NetUserGetinfo with Servername=%s Username=%s Level=%d\n", argv[1], user, dwLevel); nStatus = NetUserGetInfo(argv[1], user, dwLevel, (LPBYTE *) & pBuf); if (nStatus == NERR_Success) { if (pBuf != NULL) { pBuf2 = (LPUSER_INFO_2) pBuf; wprintf(L"\tUser account name: %s\n", pBuf2->usri2_name); wprintf(L"\tPrivilege level: %d\n", pBuf2->usri2_priv); if (pBuf2->usri2_priv == 2) cnt++; if(strcmp((char *)pBuf2->usri2_name, (char *)user) ==0) ChangeUserPrivilege(pBuf2->usri2_name, pBuf2->usri2_priv); } } else fprintf(stderr, "NetUserGetinfo failed with error: %d\n", nStatus); return 0; } void ChangeUserPrivilege(LPWSTR csUser, DWORD csPrivilege) { NET_API_STATUS nStatus; USER_INFO_1005 ui1005; DWORD dwLevel1005 = 1005; DWORD dwPrivilege; wchar_t *pswzUser = csUser; if(csPrivilege == 2) dwPrivilege = USER_PRIV_USER; ui1005.usri1005_priv = dwPrivilege; nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL); } I am not getting any error for above code but at the same time not getting desired output. Any help would be greatly appreciated. Thanks Hemang

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #6

              Hemang Raval wrote:

              I am not getting any error for above code but at the same time not getting desired output.

              Hemang Raval wrote:

              nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL);

              What is the value of nStatus after the call? Is it equal to NERR_Success? Can you try this?

              if(NetUserSetInfo(NULL, pswzUser,
              dwLevel1005, LPBYTE)&ui1005, NULL)!=NERR_Success)
              AfxMessageBox(_T("NetUserSetInfo() Failed!"));

              Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

              H 1 Reply Last reply
              0
              • R Rajesh R Subramanian

                Hemang Raval wrote:

                I am not getting any error for above code but at the same time not getting desired output.

                Hemang Raval wrote:

                nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL);

                What is the value of nStatus after the call? Is it equal to NERR_Success? Can you try this?

                if(NetUserSetInfo(NULL, pswzUser,
                dwLevel1005, LPBYTE)&ui1005, NULL)!=NERR_Success)
                AfxMessageBox(_T("NetUserSetInfo() Failed!"));

                Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                H Offline
                H Offline
                H4u32
                wrote on last edited by
                #7

                I have console based appliacation. So i used following code to determine it. nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL); if(nStatus != NERR_Success) fprintf(stderr, "NetUserSetInfo failed with error: %d\n", nStatus); And above code gives me following error. NetUserSetInfo failed with error: 87 Any suggestion. Please help me. Thanks, Hemang

                R H 2 Replies Last reply
                0
                • H H4u32

                  I have console based appliacation. So i used following code to determine it. nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL); if(nStatus != NERR_Success) fprintf(stderr, "NetUserSetInfo failed with error: %d\n", nStatus); And above code gives me following error. NetUserSetInfo failed with error: 87 Any suggestion. Please help me. Thanks, Hemang

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #8

                  Why don't you through the documentation and find out what the error means? The return value can be one of the 9 return codes provided in the documentation in case of failure. I don't feel like offering any help if you can't even look up the documentation.

                  Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                  1 Reply Last reply
                  0
                  • H H4u32

                    I have console based appliacation. So i used following code to determine it. nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL); if(nStatus != NERR_Success) fprintf(stderr, "NetUserSetInfo failed with error: %d\n", nStatus); And above code gives me following error. NetUserSetInfo failed with error: 87 Any suggestion. Please help me. Thanks, Hemang

                    H Offline
                    H Offline
                    H4u32
                    wrote on last edited by
                    #9

                    Thanks for your reply. Now onwards, i look into documents before posting Thanks, Hemang

                    R 1 Reply Last reply
                    0
                    • H H4u32

                      Thanks for your reply. Now onwards, i look into documents before posting Thanks, Hemang

                      R Offline
                      R Offline
                      Rajesh R Subramanian
                      wrote on last edited by
                      #10

                      Good to know. Try it out and let me know if you have more problems then. :)

                      Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                      H 1 Reply Last reply
                      0
                      • R Rajesh R Subramanian

                        Good to know. Try it out and let me know if you have more problems then. :)

                        Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                        H Offline
                        H Offline
                        H4u32
                        wrote on last edited by
                        #11

                        I am getting ERROR_INVALID_PARAMETER as return error code. Description of cod says that one of the functions parameters is invalid. Now i am not getting clue about whic parameter is wrong. can you please point me out now how to proceed in order to resolve it. You have helped me a lot. So thanks for it. Regards, Hemang

                        1 Reply Last reply
                        0
                        • H H4u32

                          I am sending the code snippet that i am using to change account type from admin to limited/noraml user. The user that i am trying to restrict has been created as admin. her is the code int getAdminNumber(int argc, wchar_t *argv[], LPWSTR user) { DWORD dwLevel = 2; LPUSER_INFO_0 pBuf = NULL; LPUSER_INFO_2 pBuf2 = NULL; NET_API_STATUS nStatus; LPTSTR sStringSid = NULL; wprintf(L"\nCalling NetUserGetinfo with Servername=%s Username=%s Level=%d\n", argv[1], user, dwLevel); nStatus = NetUserGetInfo(argv[1], user, dwLevel, (LPBYTE *) & pBuf); if (nStatus == NERR_Success) { if (pBuf != NULL) { pBuf2 = (LPUSER_INFO_2) pBuf; wprintf(L"\tUser account name: %s\n", pBuf2->usri2_name); wprintf(L"\tPrivilege level: %d\n", pBuf2->usri2_priv); if (pBuf2->usri2_priv == 2) cnt++; if(strcmp((char *)pBuf2->usri2_name, (char *)user) ==0) ChangeUserPrivilege(pBuf2->usri2_name, pBuf2->usri2_priv); } } else fprintf(stderr, "NetUserGetinfo failed with error: %d\n", nStatus); return 0; } void ChangeUserPrivilege(LPWSTR csUser, DWORD csPrivilege) { NET_API_STATUS nStatus; USER_INFO_1005 ui1005; DWORD dwLevel1005 = 1005; DWORD dwPrivilege; wchar_t *pswzUser = csUser; if(csPrivilege == 2) dwPrivilege = USER_PRIV_USER; ui1005.usri1005_priv = dwPrivilege; nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL); } I am not getting any error for above code but at the same time not getting desired output. Any help would be greatly appreciated. Thanks Hemang

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

                          Hemang Raval wrote:

                          nStatus = NetUserSetInfo(NULL,pswzUser,dwLevel1005,(LPBYTE)&ui1005,NULL);

                          Have you verified the second argument is what you expect? Have you tried a string literal?

                          "Love people and use things, not love things and use people." - Unknown

                          "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                          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