Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#通过WMI的Active Directory_C#_Active Directory_Wmi - Fatal编程技术网

c#通过WMI的Active Directory

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

有人举过使用WMI(System.Management命名空间)而不是System.DirectoryServices命名空间访问Active Directory、LDAP查询的例子吗

在MSDN页面上,使用CIM类对其进行了一些描述 但我找不到一些C#示例来实现这一点

例如,要访问某个Win32类,必须初始化范围对象以使用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? 谢谢:)