|
-
January 16th, 2010, 07:11 AM
#1
Issue with NetUserAdd() and NetLocalGroupAddMembers()
Hey guys!
Great to be signed up here finally, I always come here when looking for an answer to a question, but this time didn't find one 
Basically I am running under the Administrator account, so full access/privledges. I am trying to create a new user with NetUserAdd() and then add them to the "Remote Desktop Users" and "Administrators" groups (havent made it to the admin group yet) but this is my first time using the Windows API so I think I am confusing myself. Hoping maybe you guys can shed some light. The code compiles fine, the problem is that I can't figure out how I am going to specify the user account to add to the group. From what I understand, "lgrmi3_domainandname" is the name of the account your logged in on, not the one your adding. (My account creation works fine, I just cant figure out how to add them to a group without being logged on as them)
Here is my code
Code:
void AddRDPUser()
{
USER_INFO_1 ui;
DWORD dwLevel = 1;
DWORD dwError = 0;
NET_API_STATUS nStatus;
ui.usri1_name = L"BrettXFactor";
ui.usri1_password = L"XfactorsServer96";
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, 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;
}
}
}
void AddToGroup()
{
LOCALGROUP_MEMBERS_INFO_3 lgmi3;
DWORD dwLevel = 3;
DWORD totalEntries = 1;
NET_API_STATUS nStatus;
LPCWSTR TargetGroup = L"Remote Desktop Users";
LPSTR sBuffer = NULL;
memset(sBuffer, 0, 255);
DWORD nBuffSize = sizeof(sBuffer);
if(GetUserNameEx(NameDnsDomain, sBuffer, &nBuffSize)==0)
{
Msg("Failed to add User to Group\n");
return;
}
lgmi3.lgrmi3_domainandname = (LPWSTR)sBuffer;
nStatus = NetLocalGroupAddMembers(NULL, TargetGroup, 3, (LPBYTE)&lgmi3, totalEntries);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|