ユーザーが存在しませんが、Windows 7でプログラムでアカウントを作成しようとすると、ユーザーが既に存在するというエラーコードが表示されます。この問題の原因は何でしょうか?
int wmain(int argc, wchar_t *argv[])
{
USER_INFO_1 ui;
ui.usri1_name =L"test-PC";
ui.usri1_password = L"12";
ui.usri1_priv = USER_PRIV_USER;
ui.usri1_home_dir = NULL;
ui.usri1_comment = NULL;
ui.usri1_flags = UF_SCRIPT;
ui.usri1_script_path = NULL;
addUser(NULL, ui);
while(true){}
return 0;
}
int addUser(LPWSTR servername, USER_INFO_1 ui) {
DWORD dwLevel = 1;
DWORD dwError = 0;
// Call the NetUserAdd function, specifying level 1.
NET_API_STATUS nStatus = NetUserAdd(servername, dwLevel, (LPBYTE)&ui, &dwError);
// If the call succeeds, inform the user.
// Nerr_Success error code is 0 independant from nerr_base
if (nStatus == NERR_Success) {
fwprintf(stderr, L"ADD: User %s has been successfully added on %s\n", "1", "2");
return 1;
}
//Nerr_base should be given since userexists is calculated by adding nerr_base to error code
else if((NERR_BASE + nStatus) == NERR_UserExists)
fprintf(stderr, "ADD: Account already exists: %d\n", nStatus);
else if(NERR_BASE + nStatus == ERROR_ACCESS_DENIED)
fprintf(stderr, "ADD: Access Denied: %d\n", nStatus);
else if(NERR_BASE + nStatus == NERR_PasswordTooShort)
fprintf(stderr, "ADD: Password is too short: %d\n", nStatus);
else if(NERR_BASE + nStatus == NERR_PasswordTooLong)
fprintf(stderr, "ADD: Password is too long: %d\n", nStatus);
else
fprintf(stderr, "ADD: A system error has occurred2: %d\n", nStatus);
return 0;
}