Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将创建的windows用户添加到组时出现问题_C++_Windows - Fatal编程技术网

C++ 将创建的windows用户添加到组时出现问题

C++ 将创建的windows用户添加到组时出现问题,c++,windows,C++,Windows,我正在使用下面的库 Lmaccess.h netapi32.lib库 因此,我试图通过windows桌面应用程序以编程方式创建用户。我可以使用netUserAdd调用创建本地用户fine USER_INFO_1 ui1_userInfo; USER_INFO_2 ui2_userInfo; DWORD dwLevel = 2; //DWORD dwLevel = 1; DWORD dwError = 0; NET_API_STATUS nStatus; String sServerName =

我正在使用下面的库 Lmaccess.h netapi32.lib库

因此,我试图通过windows桌面应用程序以编程方式创建用户。我可以使用netUserAdd调用创建本地用户fine

USER_INFO_1 ui1_userInfo;
USER_INFO_2 ui2_userInfo;
DWORD dwLevel = 2;
//DWORD dwLevel = 1;
DWORD dwError = 0;
NET_API_STATUS nStatus;

String sServerName = NULL;
if (edit_Server->Text.Trim() != "")
{
    sServerName = edit_Server->Text.Trim();
}

populateUserInfo(ui2_userInfo);
//populateUserInfo(ui1_userInfo);
try
{
    nStatus = NetUserAdd(sServerName.c_str(), dwLevel, (LPBYTE)&ui2_userInfo, &dwError );
    //nStatus = NetUserAdd(sServerName.c_str(), dwLevel, (LPBYTE)&ui1_userInfo, &dwError );
    printStatusResult(nStatus, dwError);
}
catch (...)      //Non Delphi Exception
{
    ShowMessage("BOOM");
    //return;
}
问题是,当我尝试使用NetUserGetGroups将用户添加到组中时,我得到了一个2220,但找不到该组

NET_API_STATUS nStatus;
DWORD dwError = 1;
String sGroup = "Power Users";
String sServerName = edit_Server->Text.Trim();

nStatus = NetGroupAddUser(sServerName.c_str(), sGroup.c_str(), edit_Username->Text.c_str());
//nStatus = NetLocalGroupAddMembers(sServerName.c_str(), sGroup.c_str(), 3, (LPBYTE)&ui2_userInfo
printStatusResult(nStatus, dwError); 
我退了一步,决定尝试使用一个不是通过编程创建的用户。我也叫NetUserGetGroups

//Does work
sServerName = "vm-Win7Pro32";
String sUserName= "myUser";
DWORD dlevel = 0;
LPGROUP_USERS_INFO_0 hiME = NULL;
DWORD perfmaxlen = MAX_PREFERRED_LENGTH;
DWORD entriesread;
DWORD totalentries;
PDWORD_PTR resume_handle = NULL;
nStatus = NetUserGetGroups(sServerName.c_str(), sUserName.c_str(), dlevel, (LPBYTE*) &hiME, perfmaxlen, &entriesread, &totalentries);

if (nStatus != NERR_Success)
{
    printStatusResult(nStatus, NULL);
}
else
{
    ShowMessage(hiME->grui0_name);
}
这个家伙总是返回success,即使用户在一个组中,也不会显示None作为我的组。(至少它应该在用户组中。)

我在这里错过了什么。我是否应该调用另一个函数

参考资料 添加用户

NetGroupAddUser

NetUserGetGroups
应该使用netlocalgroupaddmembers

//
//NET_API_STATUS NET_API_FUNCTION NetLocalGroupAddMembers(
//  LPCWSTR servername,
//  LPCWSTR groupname,
//  DWORD   level,
//  LPBYTE  buf,
//  DWORD   totalentries
//);
dlevel = 3;
LOCALGROUP_MEMBERS_INFO_3 why;
String sDomainAndUser = sServerName + "\\\\" + sUserName;
why.lgrmi3_domainandname = sDomainAndUser.c_str();
nStatus = NetLocalGroupAddMembers(sServerName.c_str(), sGroup.c_str(), dlevel, (LPBYTE) &why, 1);