0
A
回答
1
那麼如果你想要做的就是將用戶添加到本地組,那麼你需要NetLocalGroupAddMembers API(無論如何用C來完成)。
舉個簡單的例子:
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);
組名稱就是你可以通過編程確定使用類似的系統組的文本名稱:
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。
0
您可以在Windows API中使用NetLocalGroupAddMembers函數。
該JEDI API Library包括一個Lan Manager Access API interface Unit,用於德爾福。
2
在這裏,您使用Jedi JCL
program Delphi_AdduserToGroup;
{$APPTYPE CONSOLE}
uses
Windows,
JclWin32,
SysUtils;
Procedure AddUsertoGroup(aUser,aGroup:PWideChar);
var
GroupMembersInfo : PLocalGroupMembersInfo3;
ResInt : Integer;
begin
GetMem(GroupMembersInfo,sizeof(TLocalGroupMembersInfo3));
try
//Writeln(aUser+'->'+aGroup);
GroupMembersInfo^.lgrmi3_domainandname :=aUser;
ResInt:=NetLocalGroupAddMembers(nil,aGroup,3,pointer(GroupMembersInfo),1);
case ResInt of
NERR_Success : Writeln('User added to group '+aGroup);
ERROR_ACCESS_DENIED : Writeln('The user does not have access to the requested information.');
ERROR_NO_SUCH_MEMBER : Writeln('One or more of the members specified do not exist. Therefore, no new members were added.');
ERROR_MEMBER_IN_ALIAS: Writeln('One or more of the members specified were already members of the local group. No new members were added.');
ERROR_INVALID_MEMBER : Writeln('One or more of the members cannot be added because their account type is invalid. No new members were added.');
else
Writeln('Error '+IntToStr(ResInt));
end;
finally
FreeMem(GroupMembersInfo);
end;
end;
begin
try
AddUsertoGroup('myuser','Administrators');
Readln;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
end.
再見的例子。
相關問題
- 1. 選擇當前用戶旁邊的組中的所有用戶
- 2. 添加字符到用戶選擇
- 3. 將當前用戶添加到管理員組
- 4. Android Facebook SDK。將當前用戶添加到Facebook羣組
- 5. 將當前用戶添加到管理員組
- 6. PowerShell - 將新用戶添加到AD組的選擇
- 7. 如何添加到Excel中的當前單元格選擇VBA
- 8. 將定義添加到UIButton的當前選擇器
- 9. NSTreeController添加:方法不添加「當前選擇後」
- 10. 如何選擇當前用戶
- 11. 當選擇JCheckBox時添加到變量
- 12. 調用當前用戶登錄的選擇項的用戶名
- 13. 如何將前一個元素添加到當前的jQuery選擇?
- 14. 選擇當前用戶的同一公司的所有用戶
- 15. 添加選擇JList組件到對象
- 16. 如何選擇當前登錄的用戶到我選定的選項值
- 17. DataGrid選擇添加的項目獨立於當前的排序
- 18. 添加當前行到表
- 19. Extjs保持組合中的當前選擇項並添加新項目
- 20. 在當前的SASS嵌套中添加祖先選擇器
- 21. 需要用戶能夠將「添加選項」添加到選擇列表中
- 22. 流星AutoForm添加用戶選擇
- 23. 根據用戶選擇添加變量
- 24. 選擇並添加到存儲過程中的變量的當前值mysql
- 25. 將當前單詞的下一個出現添加到VIM中的選擇
- 26. 無法選擇當前選擇的div
- 27. segue前用戶選擇
- 28. 循環數組將前一個值添加到當前值
- 29. 加亮選擇日期選擇器的當前周
- 30. 如何添加默認組合框「 - 選擇用戶 - 」