How to create Local User Account on Windows 2000 programatically?

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).

Thanks,
Sarah.
LVL 1
sarah81Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jkrConnect With a Mentor Commented:
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,  
                    L"%s\\%s",  
                    awcWkSta,
                    pwstrName
                );  

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

    return  (   rc);
}
0
 
sarah81Author Commented:
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
0
All Courses

From novice to tech pro — start learning today.