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