C# 获取可用域列表(NT4 和 Active Directory)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get a list of available domains (NT4 and Active Directory)
提问by Calanus
Does anyone know (in c#) a way of getting the available NT4 domains (a bit like the WinXP login box dropdown)?
有谁知道(在 c# 中)一种获取可用 NT4 域的方法(有点像 WinXP 登录框下拉列表)?
I know that this is fairly easy for Active Directory using the DirectoryServices namespace, but I can't find anything for the old NT4 domains. I'd rather not use API calls if at all possible (that might be asking a bit much however).
我知道这对于使用 DirectoryServices 命名空间的 Active Directory 来说相当容易,但我找不到旧 NT4 域的任何内容。如果可能的话,我宁愿不使用 API 调用(但这可能要求有点高)。
Also, for bonus points (!), we are finally switching to Active Directory later on this autumn, so how would I construct a way of my domain list automatically switching over from NT4 to AD, when we migrate (so I don't need to recompile and re-release)
此外,对于奖励积分(!),我们终于在今年秋天晚些时候切换到 Active Directory,那么当我们迁移时,我将如何构建域列表自动从 NT4 切换到 AD 的方式(所以我不需要重新编译和重新发布)
回答by Joseph Daigle
Unfortunately I think your only option is to use the ADSI API. You can switch between NT4 and Active Directory by changing providers in your code. NT4 uses the WinNT provider and Active Directory uses the LDAP provider.
不幸的是,我认为您唯一的选择是使用 ADSI API。您可以通过更改代码中的提供程序在 NT4 和 Active Directory 之间切换。NT4 使用 WinNT 提供程序,而 Active Directory 使用 LDAP 提供程序。
If you query the RootDSE node of whichever provider you are using, that should return naming contexts to which you can bind, including domains. RootDSE is an LDAP schema specific identifier. For WinNT you can query the root object as "WinNT:" to get available domains.
如果您查询正在使用的任何提供程序的 RootDSE 节点,则应返回您可以绑定到的命名上下文,包括域。RootDSE 是 LDAP 模式特定的标识符。对于 WinNT,您可以将根对象查询为“WinNT:”以获取可用域。
ADSI is available through VB script BTW.
ADSI 可通过 VB 脚本 BTW 获得。