与用户(CN=Users
)形成对照的是,在安装后,没有<编码>CN=Printers的集装箱。
Printers are published in Active Directory in the releated computer container. What does
releated computer container mean? Well, open Active Directory Users and Computers MMC snap-in and
follow this procedure:
- Select advanced features in the view menu.
- Select Users, Contancts, Groups and Computers as containers in the view menu.
- Navigate to the computer object (which is now displayed as container)
your printer belongs to.
- Click on the plus sign of the computer container. There you will see
the printer object.
因此,你看到打印机在改制的计算机集装箱(打印机属于)中以现成目录的形式出版,而不是放在一个共用集装箱内,如<编码>CN=Printers。
So, to search for a printer object in Active Directory, you have to specify
a different LDAP path. For example you could specify the root of your Active Directory
as the search root:
using (DirectoryEntry entry = new DirectoryEntry())
{
entry.Path = "LDAP://xxx.xxx.xxx.xxx/DC=domainName,DC=com";
entry.Username = @"domainName.comAdministrator";
entry.Password = "SecurePassword";
using (DirectorySearcher search = new DirectorySearcher(entry))
{
search.Filter = "(objectCategory=printQueue)";
SearchResult result = search.FindOne();
if (result != null)
{
ResultPropertyCollection fields = result.Properties;
foreach (String ldapField in fields.PropertyNames)
{
foreach (Object myCollection in fields[ldapField])
Console.WriteLine(String.Format("{0,-20} : {1}",
ldapField, myCollection.ToString()));
}
}
}
}
Of course, you could also specify as search root the LDAP path to the computer where your printer
is shared on. For example if your printer is shared on a computer called server10
and this computer is located in the CN=Computers
container, then specify this LDAP path:
LDAP://xxx.xxx.xxx.xxx/CN=server10,CN=Computers,DC=domainName,DC=com
If you share a printer on the domain controller then the LDAP path is slightly different (because by default domain controller computer objects are located in the OU=Domain Controllers
organizational unit):
LDAP://xxx.xxx.xxx.xxx/CN=DomainControllerName,OU=Domain Controllers,DC=domainName,DC=com