[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

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?
0
nvenkat
Asked:
nvenkat
1 Solution
 
jkrCommented:
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",
                            rc,
                            dwParmErr
                        );

            return  (   rc);
        }

    return  (   0);
}

0

Featured Post

SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now