开发者

c# Active Directory via WMI

开发者 https://www.devze.com 2023-01-03 11:22 出处:网络
Does anyone has some example about accessing Active Directory, LDAP querying using WMI (System.Management namespace) and not System.DirectoryServices namespace.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消