4
A
回答
4
样品伪代码:
String SelectUsers(HWND hwndParent, IList<String> usersLdapPaths)
{
IDsObjectPicker objPicker;
IDataObject objData;
PDSOP_INIT_INFO pInfo;
LPWSTR[0..2] attr;
HRESULT hr;
/*
Returns the LDAP path to the selected user, e.g.:
LDAP://stackoverflow.com/CN=Ian Boyd,OU=Stack Users,DC=stackoverflow,DC=com
usersLdapPaths can be null.
If not null then the user can mutli-select users,
and the selected user's LDAP paths will be returned in usersLdapPaths
(with the function result containing just the first user)
If the user cancels the dialog, then the result (and usersLdapPaths) will be empty
*/
Result := '';
objPicker = CreateComObject(CLSID_DsObjectPicker) as IDsObjectPicker;
System.New(pInfo);
try
{
ZeroMemory(pInfo, SizeOf(DSOP_INIT_INFO));
pInfo.cbSize = SizeOf(DSOP_INIT_INFO);
pInfo.pwzTargetComputer = nil; //local computer
pInfo.cDsScopeInfos := 1;
System.New(pInfo.aDsScopeInfos);
try
{
ZeroMemory(pInfo.aDsScopeInfos, SizeOf(DSOP_SCOPE_INIT_INFO));
pInfo.aDsScopeInfos.cbSize = SizeOf(pInfo.aDsScopeInfos);
pInfo.aDsScopeInfos.flType = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN; //or DSOP_SCOPE_TYPE_TARGET_COMPUTER;
pInfo.aDsScopeInfos.flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP;
pInfo.aDsScopeInfos.FilterFlags.Uplevel.flBothModes = DSOP_FILTER_USERS;
pInfo.aDsScopeInfos.FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_USERS;
if (UsersLdapPaths != null)
pInfo.flOptions = DSOP_FLAG_MULTISELECT;
pInfo.cAttributesToFetch := 3;
attr[0] = "description";
attr[1] = "name";
attr[2] = "fullName";
pInfo.apwzAttributeNames = @attr;
hr = objPicker.Initialize(pInfo);
OleCheck(hr);
hr = objPicker.InvokeDialog(hwndParent, objData);
OleCheck(hr);
//the result is false if the user cancelled the dialog
if hr = S_FALSE then
return '';
return ReadAttributes(objData, UsersLdapPaths);
}
finally
{
System.Dispose(pInfo.aDsScopeInfos);
}
}
finally
{
Dispose(pInfo);
}
}
和辅助功能(我不会打扰从一个伪语言代码转换到另一种语言的伪代码):
function TActiveDirectory.ReadAttributes(ADataObject: IDataObject; AValues: TStrings): string;
var
fmtIn: TFormatEtc;
stgOut: TStgMedium;
pSelList: PDS_SELECTION_LIST;
i: Integer;
path: string;
// x: LongWord;
// pVar: POleVariant;
items: PDsSelectionArray;
begin
Result := '';
if Assigned(AValues) then
AValues.Clear;
if not Assigned(ADataObject) then
Exit;
stgOut.tymed := TYMED_HGLOBAL;
fmtIn.tymed := TYMED_HGLOBAL;
fmtIn.cfFormat := RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
fmtIn.dwAspect := DVASPECT_CONTENT;
fmtIn.lindex := -1;
if (ADataObject.GetData(fmtIn, stgOut) <> S_OK) then
Exit;
pSelList := GlobalLock(stgOut.hGlobal);
try
if pSelList.cItems > 0 then
items := PDsSelectionArray(@pSellist.aDsSelection)
else
items := nil;
for i := 0 to pSelList^.cItems-1 do
begin
// path := TDsSelectionArray(pSellist.aDsSelection)[i].pwzADsPath;
path := items[i].pwzADsPath;
if Assigned(AValues) then
AValues.Add(path);
if Result = '' then
Result := path;
{ Result := pSelList^.aDsSelection[i].pwzName+' ('+pSelList.aDsSelection[i].pwzADsPath+')';
AValues.Add(Result);
AValues.Add(' Class: '+pSelList^.aDsSelection[i].pwzClass); //"user"
AValues.Add(' UPN: '+pSelList^.aDsSelection[i].pwzUPN); //e.g. "[email protected]"
pVar := pSelList^.aDsSelection[i].pvarFetchedAttributes;
for x := 0 to pSelList^.cFetchedAttributes-1 do
begin
AValues.Add(' '+VarToStr(pVar^));
if x < pSelList^.cFetchedAttributes then
Inc(pVar);
end;}
end;
finally
GlobalUnlock(stgOut.hGlobal);
end;
end;
0
6
如果您正在寻找我们已经创建了一个可在的NuGet一个https://github.com/Tulpep/Active-Directory-Object-Picker .NET解决方案。
它基于此项目https://adui.codeplex.com/,但更新为x64计算机。
相关问题
- 1. Active Directory检查用户是否登录
- 2. 文本框,其行为类似于Active Directory中的多个对象选择对话框
- 3. Active Directory共享邮箱用户权限
- 4. 检查用户是否存在于Active Directory中
- 5. 检查用户名是否存在于Microsoft Azure Active Directory中
- 6. 是否有用于Active Directory查询的分析器?
- 7. 如何选择Active Directory的所有组?
- 8. 如何验证用户是否属于C#.NET中的Active Directory用户组。
- 9. 如何检查Active Directory组是否是另一个Active Directory组的成员
- 10. 制作一个允许用户选择文件的对话框
- 11. 使用Powershell更新Active Directory中的Active Directory用户属性
- 12. 获取Active Directory中的所有用户
- 13. CSV导出脚本对Active Directory用户
- 14. 如何在Azure Active Directory中授权而不使用对话框?
- 15. Active Directory是否需要用户禁用代码片段?
- 16. Azure Active Directory图Api - 用户
- 17. Umbraco Active Directory创建用户
- 18. 验证Active Directory用户
- 19. 是否有一个打开的对话框来选择Jar内的文件?
- 20. 对于Active Directory中的任何条目,DistinguishedName是否改变?
- 21. 是否有用于私有公共虚拟方法的用例?
- 22. 查找用户是否为Active Directory组ASP.NET VB的成员?
- 23. 看看用户是否是C#+ Asp.net中的Active Directory组的一部分
- 24. asp.net web应用程序 - 检查用户是否存在于Active Directory组中
- 25. 什么是使用CFontDialog公共对话框的正确方法?
- 26. 是否有一个适用于移动设备的JQuery的JavaScript对话框?
- 27. ASP.NET MVC5 - 使用Active Directory用户的DropDownList
- 28. 使用Rails的Active Directory用户联合?
- 29. 检测用户是否必须重置密码在Active Directory中
- 30. 检查Azure Active Directory中是否存在用户B2C
这可作为NuGet https://github.com/Tulpep/Active-Directory-Object-Picker – 2014-10-29 15:52:43