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);
}
Issue with NetUserAdd() and NetLocalGroupAddMembers()
Hey all,
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)
Ah awesome, that was my mistake then. One other question then, how do you get the domain of another user?
Well, since you use NetUserAdd to add the user, they're in the local domain. A shortcut for the local domain is "." so you should just be able to specify that.
Ah that makes life easier :)
This should be the last question, but I am getting "the connection was denied because the user is not authorized for remote login" when I attempt to connect with any of the accounts. I double checked the box, and it did indeed add the account, but it didn't add it to the group. I printed out the error log and it was "STATUS: ERROR_NO_SUCH_MEMBER". Heres my updated code for AddToGroup()
This should be the last question, but I am getting "the connection was denied because the user is not authorized for remote login" when I attempt to connect with any of the accounts. I double checked the box, and it did indeed add the account, but it didn't add it to the group. I printed out the error log and it was "STATUS: ERROR_NO_SUCH_MEMBER". Heres my updated code for AddToGroup()
void AddToGroup(){ LOCALGROUP_MEMBERS_INFO_3 lgmi3; DWORD dwLevel = 3; DWORD totalEntries = 1; NET_API_STATUS nStatus; LPCWSTR TargetGroup = L"Remote Desktop Users"; LPWSTR DomainUser = L".\\BrettXFactor"; lgmi3.lgrmi3_domainandname = DomainUser; nStatus = NetLocalGroupAddMembers(NULL, TargetGroup, 3, (LPBYTE)&lgmi3, totalEntries); if(nStatus == NERR_Success) { Msg("Added to Group Successfully!\n"); } else { Msg("Add to Group Failed!\n"); }}
Im about to pass out, just wanted to pop back in here and say thanks to you and MaulingMonkey in the irc chat, I got this working. The issue was the .\\ for the domain. By removing it completely it worked fine.
So thanks very much, and to anyone who runs into this in the future, theres your fix, dont use a domain at all for that struct if its a local host.
So thanks very much, and to anyone who runs into this in the future, theres your fix, dont use a domain at all for that struct if its a local host.
Quote:Original post by CrimsonGTYeah, that would've been my next guess :)
Im about to pass out, just wanted to pop back in here and say thanks to you and MaulingMonkey in the irc chat, I got this working. The issue was the .\\ for the domain. By removing it completely it worked fine.
So thanks very much, and to anyone who runs into this in the future, theres your fix, dont use a domain at all for that struct if its a local host.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement