• C

Creation of user account in NT Server

I want to create an username account and password in an NT Server using C programming. I want to use this as my default username and password to do FTP process from a client machine(NT Server/Workstation).
How do I proceed?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You'll have to use the LAN Manager API 'NetUserAdd()' (UNICODE!):

#include <tchar.h>
#include <lmcons.h>
#include <lmerr.h>
#include <lmaccess.h>
#include <lmapibuf.h>

#pragma comment ( lib, "netapi32.lib")

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

    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"";

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

    if  (   NERR_Success    !=  rc)
            wprintf     (   L"Unable to 'NetUserAdd()', code == %d, parm err == %d\n",

            return  (   rc);

    return  (   0);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.