c# Active Directory via WMI

Posted by Juri Bogdanov on Stack Overflow See other posts from Stack Overflow or by Juri Bogdanov
Published on 2010-06-16T11:08:50Z Indexed on 2010/06/16 11:12 UTC
Read the original article Hit count: 410

Filed under:
|
|

Hi! 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 :)

© Stack Overflow or respective owner

Related posts about c#

Related posts about active-directory