当前/选择的用户添加到组 [英] add current/selected user to a group
本文介绍了当前/选择的用户添加到组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我我怎么能(编程)当前/选择的用户添加到组(如电力用户,备份opetarors)
can anyone tell me how can I (programatically) add the current/selected user to a group (like power user, backup opetarors)
任何功能/信息/ code是值得欢迎的。
any function/info/code is welcomed
推荐答案
好吧,如果你想要做的就是将用户添加到本地组,那么你想要的NetLocalGroupAddMembers API(做用C反正)。
Well if all you want to do is add a user to a local group then you want the NetLocalGroupAddMembers API (to do it in C anyway).
作为一个简单的例子:
LOCALGROUP_MEMBERS_INFO_3 member[1];
// Add using fully qualified name, could also use SID with LOCALGROUP_MEMBERS_INFO_0
member[0].lgrmi3_domainandname = L"MAIN\\username";
status = NetLocalGroupAddMembers(NULL, L"Power Users", 3, (LPBYTE)member, 1);
组名称就是你可以编程确定使用类似的系统组的文本名称:
The group name is just the textual name of the group on the system which you can determine programatically using something like:
PLOCALGROUP_INFO_0 groups = NULL;
DWORD dwCount = 0;
DWORD dwTotalCount = 0;
NET_API_STATUS status = NetLocalGroupEnum(NULL, 0, (LPBYTE*)&groups, MAX_PREFERRED_LENGTH, &dwCount, &dwTotalCount, NULL);
if(status == NERR_Success)
{
for(DWORD i = 0; i < dwCount; i++)
{
printf("%ls\n", groups[i].lgrpi0_name);
}
NetApiBufferFree(groups);
}
else
{
printf("Error %d\n", status);
}
添加到全局组,您需要改用NetGroupAddUser API。
Adding to global group you will need to instead use the NetGroupAddUser API.
这篇关于当前/选择的用户添加到组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文