views:

87

answers:

1

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

+1  A: 

check the following links
http://msdn.microsoft.com/en-us/library/aa392320(v=VS.85).aspx
http://www.winfrastructure.net/article.aspx?BlogEntry=Get-Active-Directory-users-using-WMI

Space Cracker
I'm sure the OP could have Googled that. This question deserves a code sample.
David Neale
Ok thanks :)As I understood, namespace should be changed from \root\CIMV2 to \root\Directory\LDAPAnd WQL should look likeSELECT * from DS_Computer where DS_Name = ...
Juri Bogdanov