C# 通过 WMI 的 Active Directory
有没有人有一些关于访问 Active Directory、使用 WMI(System.Management 命名空间)而不是 System.DirectoryServices 命名空间进行 LDAP 查询的示例。
在 MSDN 页面上,它使用 CIM 类进行了一些描述 http://msdn.microsoft.com/en -us/library/aa392320(v=VS.85).aspx 但我找不到一些实现它的 C# 示例。
例如,要访问某些 Win32 类,您必须初始化 Scope 对象以使用 CIMV2 命名空间
private ConnectionOptions connection;
private ManagementScope scope;
...
connection = new ConnectionOptions();
...
scope = new ManagementScope("\\\\" + computer + "\\root\\CIMV2", connection);
try
{
scope.Connect();
}
并使用 ObjectQuery 类来查询 WMI 数据
ObjectQuery objectQuery = new ObjectQuery("SELECT Name FROM Win32_Processor");
ManagementObjectSearcher searcher = ManagementObjectSearcher(scope, objectQuery);
foreach (ManagementObject queryObj in searcher.Get())
{
return queryObj["Name"].ToString();
}
如何使用相同的范围访问 AD? 谢谢 :)
Does anyone has some example about accessing Active Directory, LDAP querying using WMI (System.Management namespace) and not System.DirectoryServices namespace.
Here on MSDN page it is described a little using CIM classes
http://msdn.microsoft.com/en-us/library/aa392320(v=VS.85).aspx
But I cant find some C# example realizing it.
For example, to access some Win32 class you have to initialize Scope object to use CIMV2 namespace
private ConnectionOptions connection;
private ManagementScope scope;
...
connection = new ConnectionOptions();
...
scope = new ManagementScope("\\\\" + computer + "\\root\\CIMV2", connection);
try
{
scope.Connect();
}
And use ObjectQuery class for querying WMI data
ObjectQuery objectQuery = new ObjectQuery("SELECT Name FROM Win32_Processor");
ManagementObjectSearcher searcher = ManagementObjectSearcher(scope, objectQuery);
foreach (ManagementObject queryObj in searcher.Get())
{
return queryObj["Name"].ToString();
}
How is it possible to access AD using the same scope?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论