Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 275565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:47:07+00:00 2026-05-12T00:47:07+00:00

I am calling NetUserAdd and it is returning 24 for every call. Does anyone

  • 0

I am calling NetUserAdd and it is returning 24 for every call. Does anyone know what 24 stands for? It is kind of hard to debug it when I don’t know what the error means.

I am calling this from an Windows XP machine running as a local admin. I am also a local admin on the target computer. I tried this with USER_INFO_1 and it worked fine. I just need the level of control given by USER_INFO_2.

This link shows the return values for this call. They are further defined here with numeric values. Sadly none of these values = 24.

I know this is a very specific question. I guess I am hoping to find a PInvoke/NetAddUser expert out there who can help me out.

Here is my code in case it matters:

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct USER_INFO_2
    {
        public string name;
        public string password;
        public int password_age;
        public int priv;
        public string home_dir;
        public string comment;
        public int flags;
        public string script_path;
        public int auth_flags;
        public string full_name;
        public string usr_comment;
        public string parms;
        public string workstations;
        public int last_logon;
        public int last_logoff;
        public ulong acct_expires;
        public int max_storage;
        public int units_per_week;
        public IntPtr logon_hours;    // This is a PBYTE
        public int bad_pw_count;
        public int num_logons;
        public string logon_server;
        public int country_code;
        public int code_page;
    }

    [DllImport("netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    private static extern int NetUserAdd(
         [MarshalAs(UnmanagedType.LPWStr)] string servername,
         UInt32 level,
         ref USER_INFO_2 userinfo,
         out UInt32 parm_err); 

    private static uint CreateUser(string computer, string userName,
       string psswrd, string fullname)
    {
        const int UF_DONT_EXPIRE_PASSWD = 0x10000;
        const int UF_ACCOUNTDISABLE = 0x000002;

        const int USER_PRIV_GUEST = 0; // lmaccess.h:656
        const int USER_PRIV_USER = 1;   // lmaccess.h:657
        const int USER_PRIV_ADMIN = 2;  // lmaccess.h:658

        USER_INFO_2 userInfo2 = new USER_INFO_2()
        {
            acct_expires = long.MaxValue,
            auth_flags = 0, // Must be 0 for NetUserAddCalls
            bad_pw_count = -1,  //ignored for NetUserAdd calls
            //code_page = ?,
            comment = "ScanTrack Account",
            //country_code = ?,
            flags = UF_DONT_EXPIRE_PASSWD,// & UF_ACCOUNTDISABLE,
            full_name = fullname,
            home_dir = "",
            last_logoff = 0,
            last_logon = 0,
            logon_hours = IntPtr.Zero, // User is given no logon time.
            logon_server = "", //ignored for NetUserAdd calls
            max_storage = 0,
            name = userName,
            num_logons = -1, //ignored for NetUserAdd calls
            parms = "",
            password = psswrd,
            password_age = -1,
            priv = USER_PRIV_GUEST,
            script_path = "",
            units_per_week = -1, //ignored for NetUserAdd calls
            usr_comment = "",
            workstations = ""
        };

        uint output;
        NetUserAdd(computer, 2, ref userInfo2, out output);
        return output;
    }

    private void button1_Click(object sender, EventArgs e)
    {

        string computer = "ComputerName";
        string userName = "testName";
        string psswrd = "!t3st4Stuff";
        string fullname = "Test Name Full";

        uint output = CreateUser(computer, userName, psswrd, fullname);
        MessageBox.Show(output.ToString());
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:47:08+00:00Added an answer on May 12, 2026 at 12:47 am

    From Error.h:

    #define ERROR_BAD_LENGTH        24
    

    …not sure how that relates to your code, but there it is.

    Edit: I wonder whether it’s this:

    home_dir = ""
    

    or similar – the documentation says “Pointer to a Unicode string specifying the path of the home directory for the user specified by the usri2_name member. The string can be null.” – there’s no mention of the string being given but empty, as you have it. Try null – maybe zero length strings can mean ERROR_BAD_LENGTH..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 162k
  • Answers 162k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This kind of problem is known as federated database systems.… May 12, 2026 at 12:01 pm
  • Editorial Team
    Editorial Team added an answer or datename(dw,getdate()) May 12, 2026 at 12:01 pm
  • Editorial Team
    Editorial Team added an answer This is a complicated situation, as it seems the "{http://xml.apache.org/xalan}omit-meta-tag"… May 12, 2026 at 12:01 pm

Related Questions

I am calling a vendor's Java API, and on some servers it appears that
I am calling a WSDL web service from Python using SOAPpy . The call
I am calling a SQL proc that has 3 OUTPUT params. After the call
I am calling a csh script that the first thing it does is starts

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.