Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


How to create Local User Account on Windows 2000 programatically?

Posted on 2004-10-28
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 12434092
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);

Author Comment

ID: 12450284
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 methods...so this is cooool... thanks a lot :D

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

618 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