How to create Local User Account on Windows 2000 programatically?

Posted on 2004-10-28
Last Modified: 2013-12-03
I have to write a simple application that is supposed to create a user on the local machine. Any idea how we can do it on Windows 2000?? I have used ADSI routines. They dont work on all machines. Is there any other way to do it?? Some Win32 API etc?? Its urgent work. 500 points to whoever gives me the right solution. plz dont suggest using ADSI (directory services , i know how to do it using that).

Question by:sarah81
    LVL 86

    Accepted Solution

    Use 'NetUserAdd()', e.g.

    AddNewUser  (  
        LPWSTR  pwstrName,
        LPWSTR  pwstrPwd,
        LPWSTR  pwstrComment
        NET_API_STATUS              rc;
        USER_INFO_1                 ui1;

        wchar_t                     awcDomUsrName       [   LM20_DNLEN  +   LM20_UNLEN  +   1];
        wchar_t                     awcWkSta            [   MAX_COMPUTERNAME_LENGTH + 2];
        DWORD                       dwBufSiz            =   MAX_COMPUTERNAME_LENGTH + 1;

        ZeroMemory  (   &ui1,   sizeof (    USER_INFO_1));

        ui1.usri1_name          =   pwstrName;
        ui1.usri1_password      =   pwstrPwd;
        ui1.usri1_password_age  =   0;
        ui1.usri1_priv          =   USER_PRIV_USER;
        ui1.usri1_flags         =   UF_DONT_EXPIRE_PASSWD | UF_NORMAL_ACCOUNT | UF_SCRIPT;
        ui1.usri1_home_dir      =   L"";
        ui1.usri1_comment       =   pwstrComment;
        ui1.usri1_script_path   =   L"";

        GetComputerName (   awcWkSta,   &dwBufSiz);

        wsprintf    (   awcDomUsrName,  

        rc  =   NetUserAdd  (   NULL,   1,  ( LPBYTE) &ui1, &dwParmErr);

        return  (   rc);
    LVL 1

    Author Comment

    Thanks jkr, that was great help. And I found that my activeds solution wasnt wrong either. it was the just password that i was setting up wrong. but this NetUserAdd() is too fast than activeds this is cooool... thanks a lot :D

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Shellfire Box VPN + Lifetime Subscription

    The Shellfire Box easily connects all of your devices, even those that don't offer the possibility to establish a safe vpn connection. Access blocked content and surf safely, no matter where in the world you are located.

    This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    845 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now