开发者

Help Using NetuserAdd() and NetLocalGroupAddMembers() in C++

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


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";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜