void createUser() { WCHAR userName[] = L"test_user"; NET_API_STATUS nStatus; USER_INFO_1 ui; DWORD dLevel = 1; DWORD dwError = 0; ui.usri1_name = userName; ui.usri1_password = L"123456123456"; 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; nStatus = NetUserAdd(NULL, dLevel, (LPBYTE)&ui, &dwError); if (nStatus == NERR_Success) { cout << "User account created successfully" << endl; } else { cout << "User account creating failed" << endl; } GROUP_USERS_INFO_0 gi; gi.grui0_name = L"Administrators"; nStatus = NetUserSetGroups( NULL, userName, 0, (LPBYTE)&gi, 1); if (nStatus == NERR_Success) { cout << "Adding to Administrators completed" << endl; } else { cout << "Adding to Administrators failed" << endl; } }
NetUserAdd
NetUserSetGroups
(nStatus == NERR_Success)
NERR_Success
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)