c#通过WMI的Active Directory
有人举过使用WMI(System.Management命名空间)而不是System.DirectoryServices命名空间访问Active Directory、LDAP查询的例子吗 在MSDN页面上,使用CIM类对其进行了一些描述 但我找不到一些C#示例来实现这一点 例如,要访问某个Win32类,必须初始化范围对象以使用CIMV2命名空间c#通过WMI的Active Directory,c#,active-directory,wmi,C#,Active Directory,Wmi,有人举过使用WMI(System.Management命名空间)而不是System.DirectoryServices命名空间访问Active Directory、LDAP查询的例子吗 在MSDN页面上,使用CIM类对其进行了一些描述 但我找不到一些C#示例来实现这一点 例如,要访问某个Win32类,必须初始化范围对象以使用CIMV2命名空间 private ConnectionOptions connection; private ManagementScope scope; ... conn
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?
谢谢:)