能提供资料者可另外给分

解决方案 »

  1.   

    DWORD CNetUsers::Add(CString strServerName, CString strUserName, CString strPassword)
    {
    USER_INFO_1 user_info;
    LPWSTR lpszUserName = (LPWSTR)strUserName.AllocSysString();
    LPWSTR lpszPassword = (LPWSTR)strPassword.AllocSysString();
    LPWSTR lpszServerName = (LPWSTR)strServerName.AllocSysString();
    NET_API_STATUS nStatus = 0;
    DWORD parm_err = 0;
    DWORD dwLevel = 1; // Set up the USER_INFO_1 structure. 
        user_info.usri1_name = lpszUserName;
        user_info.usri1_password = lpszPassword;
        user_info.usri1_priv = USER_PRIV_USER;
        user_info.usri1_home_dir = (LPWSTR)"";
        user_info.usri1_comment = NULL;
        user_info.usri1_flags = UF_SCRIPT;
        user_info.usri1_script_path = (LPWSTR)""; if (strServerName.IsEmpty())
    {
    nStatus = NetUserAdd(NULL,
    dwLevel,
    (LPBYTE)&user_info,
    &parm_err);
    }
    else
    {
    nStatus = NetUserAdd(lpszServerName,
    dwLevel,
    (LPBYTE)&user_info,
    &parm_err);
    }    if ( nStatus != NERR_Success  )
        {
    if(m_bShowMessage == TRUE)
    {
    DisplayErrorText(nStatus);
    }        
        }
    else
    {
    CString csTemp;
    csTemp.Format("已经成功添加帐号%s。",strUserName);
    AfxMessageBox(csTemp);
    } if(nStatus == NERR_UserExists)
    nStatus = NERR_Success; if(nStatus == NERR_Success)
    m_strUserName = strUserName;
        
    return nStatus;
    }