tags:

views:

106

answers:

1

I posted earlier about how to do this, and got some great replies, and have managed to get the code written based off the MSDN example. However, it does not seem to be working properly. Its printing out the ERROR_ACCESS_DENIED message, but im not sure why as I am running it as a full admin. I was initially trying to create a USER_PRIV_ADMIN, but the MSDN said it can only use USER_PRIV_USER, but sadly neither work. Im hoping someone can spot a mistake or has an idea.

Thanks!

void AddRDPUser()
{
    USER_INFO_1 ui;
    DWORD dwLevel = 1;
    DWORD dwError = 0;
    NET_API_STATUS nStatus;

    ui.usri1_name = L"DummyUserAccount";
    ui.usri1_password = L"a2cDz3rQpG8";
    //ignored by NetUserAdd
    //ui.usri1_password_age = -1;
    ui.usri1_priv = USER_PRIV_USER; //USER_PRIV_ADMIN;
    ui.usri1_home_dir = NULL;
    ui.usri1_comment = NULL;
    ui.usri1_flags = UF_SCRIPT;
    ui.usri1_script_path = NULL;

    nStatus = NetUserAdd(NULL, dwLevel, (LPBYTE)&ui, &dwError);

    switch (nStatus)
    {
        case NERR_Success:
        {
            Msg("SUCCESS!\n");
            break;
        }
        case NERR_InvalidComputer:
        {
            fprintf(stderr, "A system error has occurred: NERR_InvalidComputer\n");
            break;
        }
        case NERR_NotPrimary:
        {
            fprintf(stderr, "A system error has occurred: NERR_NotPrimary\n");
            break;
        }
        case NERR_GroupExists:
        {
            fprintf(stderr, "A system error has occurred: NERR_GroupExists\n");
            break;
        }
        case NERR_UserExists:
        {
            fprintf(stderr, "A system error has occurred: NERR_UserExists\n");
            break;
        }
        case NERR_PasswordTooShort:
        {
            fprintf(stderr, "A system error has occurred: NERR_PasswordTooShort\n");
            break;
        }
        case ERROR_ACCESS_DENIED:
        {
            fprintf(stderr, "A system error has occurred: ERROR_ACCESS_DENIED\n");
            break;
        }
    }
}
A: 

Is you os vista or win 7?, if so then you may need to raise your privilege level.

deadpoint
Windows 7, it will be running on Server 2008 though. I wasnt aware of that, guess I will go try it there instead and see if it actually works. Thanks :)
Brett Powell