tags:

views:

115

answers:

1

So I think I almost got it. I create my dummy account with one function, and wrote a second function to add it to the Remote Desktop group. Problem is, the Administrator account is the one logged in, so I am not sure how to specify what account to add to the group. Here is my code...

The user is being created properly...

 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);
 }

But I dont know how to specify to add them to this group since they are not logged in. Any help would be appreciated

 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;
     }

     LPWSTR user_name = (LPWSTR)sBuffer;
     lgmi3.lgrmi3_domainandname = user_name;

     nStatus = NetLocalGroupAddMembers(NULL, TargetGroup, 3,
         (LPBYTE)&lgmi3, totalEntries);
 }
A: 

No offense, but you don't seem to know what you're doing with the code at all. You're not adding the current user to the target group; you're adding the user you just created to it right? Then why are you calling GetUserNameEx? Just use the name of the new user:

lgmi3.lgrmi3_domainandname = L"BrettXFactor";
wj32
I got this working, your right though, I was confused out of my skull. I was trying to use GetUserNameEx to get the domain they belonged to, but someone mentioned that since I created it, they were in the local domain. Thanks for the help!
Brett Powell