我需要编写一个.NET应用程序,它将在尚未成为域成员的计算机上运行Windows PE时查询Active Directory。
我们在Microsoft Deployment Toolkit任务序列期间运行此操作(请注意,MDT 2012已配置为将.NET支持加载到WinPE环境中 - .NET应用程序正在启动而没有任何问题。)
我使用下面的代码绑定到域:
DirectoryEntry entry = new DirectoryEntry(
path,
username,
password,
AuthenticationTypes.ServerBind | AuthenticationTypes.Secure);
我尝试了path
这两种形式:
LDAP://domainServer/dc=domain,dc=name
并且没有域控制器名称
LDAP://dc=domain,dc=name
我还尝试使用username
表单domain\username
以及username
表单。
DirectoryEntry
对象似乎构造正常,但是当我尝试执行Console.Writeline(entry.Name)
以确认已建立有效连接时,我得到以下异常:
System.Runtime.InteropServices.COMException(0x80005000):未知 错误(0x80005000)at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
在System.DirectoryServices.DirectoryEntry.Bind()at System.DirectoryServices.DirectoryEntry.get_Name()
我已经尝试过对此代码的其他变体,尝试使用各种过滤器执行LDAP查询,尝试在VBScript中重写它等等...但上面发布的代码是我能提出的最简单的示例,可以重现问题
根据我的阅读,在这样的场景中,您总是需要使用AuthenticationTypes.ServerBind
,这就是我尝试在ADSI LDAP路径中指定代码的原因。但是上面的代码有什么问题?对我来说,看起来它将参数中的所有必需信息传递给DirectoryEntry
构造函数。
答案 0 :(得分:1)
有一种方法可以让它发挥作用,但微软并不支持它。这篇文章给了我很多帮助。它的工作,测试和批准用于部署新计算机:)
从zip文件中获取ADSIxXX.inf
到C:\ADSI
将以下文件从Windows / System32复制到C:\ADSI
。小心建筑
x86 x64
-
adsldp.dll
adsmsext.dll
adsnt.dll
mscoree.dll
mscorier.dll
mscories.dll
挂载{{1}}
无需加载Package(您的WinPE已配置为加载.NET API),juste添加ADSI驱动程序:
bootimage.wim
无需加载他的剧本
卸载Dism /Image:C:\Mount /Add-Driver /Driver:C:\ADSI\ADSIxXX.inf /forceunsigned
如果您的.NET应用程序实现良好,那么就完成了;)
我不是PIPE |也支持作为参数,只需设置为bootimage.wim
-
AuthenticationTypes.Secure