Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:55:22+00:00 2026-06-03T07:55:22+00:00

Attempting to find printers / shares in Active Directory using C#. This is my

  • 0

Attempting to find printers / shares in Active Directory using C#.

This is my sample code that works for users however I cannot seen to be able to find a printer using the same concept. (I am new to Active Directory).

    DirectoryEntry entry = new DirectoryEntry();
    entry.Path = "LDAP://xxx.xxx.xx.xx/CN=Printers;DC=domainName, DC=com";
    entry.Username = @"domainName.com\Administrator";
    entry.Password = "admin";

    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()));
        }
    }

Any assistance would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:55:24+00:00Added an answer on June 3, 2026 at 7:55 am

    In contrast to users (CN=Users) there is no CN=Printers container in Active Directory after installation.

    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:

    1. Select advanced features in the view menu.
    2. Select Users, Contancts, Groups and Computers as containers in the view menu.
    3. Navigate to the computer object (which is now displayed as container)
      your printer belongs to.
    4. Click on the plus sign of the computer container. There you will see
      the printer object.

    So, you see printers are published in Active Directory in the releated computer container (the printer belongs to) and not in one common container such as 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.com\Administrator";
      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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to find a solution to allow users to sort content that is
I am attempting to find a binary file in a Linux system using something
I'm writing a Clojure implementation of this coding challenge , attempting to find the
I have the following code inside a Form, and am attempting to find a
Here is my code, I have been attempting to find a way to do
I am attempting to find a place to start debugging this issue at. I
I am attempting to find 'entries' create today (in my current timezone) using the
I am attempting to find the MAC address using pcap for a small project.
All, I am attempting to find a control by name within a TabControl. However
In Grails, I'm attempting to find an instance of a domain class that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.