none
How to retrive DomainController information in 1.1 framework RRS feed

  • Question

  • Hello ,

     we have a requirment where we need to support 1.1 framework environments, for that we need to convert .net 2.0 framework code to 1.1. We are facing a problem to get doamin controller information, if any one could give me the equivalent code for the following that would be really great.

    DirectoryContext dirContext = new DirectoryContext(DirectoryContextType.Domain, strDomainName);

                    DomainControllerCollection dcCollection = DomainController.FindAll(dirContext);

    i need these 2 lines in 1.1 framework. I have done some search over net but did not find a valid input. Any help would be appreciated.

    Thanks

    Kiran Reddy.

    Monday, September 10, 2012 2:41 PM

Answers

  • You need to work with DirectorySearcher class to find domain conrollers. You can read documentation at http://msdn.microsoft.com/en-us/library/9t2667d1(v=vs.71) about how to work with directory services in .NET 1.1.

    There's not much examples about subject, but there is great book The .NET Developer's Guide to Directory Services that includes both .NET 1.1 and 2.0.

    Tuesday, September 11, 2012 8:42 AM
  • Use ADO.Net OleDbConnection (not sure if this is optimal)

    string logon = Environment.GetEnvironmentVariable("logonserver").TrimStart('\\');
    string queryOU = string.Format(@"<LDAP://{0}>;(&(objectCategory=organizationalUnit)(objectClass=organizationalUnit)(ou=Domain\20Controllers));distinguishedName;subTree", logon);
    string queryDC = @"<LDAP://{0}>;(objectClass=computer);distinguishedName;subTree";
    var constr = "Provider=ADsDSOObject;Encrypt Password=False;Data Source=ADs Provider;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648;";
    ArrayList domainControllers = new ArrayList();
    using (OleDbConnection connection = new OleDbConnection(constr))
    {
        connection.Open();
        using (IDbCommand ouCommand = connection.CreateCommand())
        {
            ouCommand.CommandText = queryOU;
            using (IDataReader ouReader = ouCommand.ExecuteReader())
            {
                while (ouReader.Read())
                {
                    using (IDbCommand dcCommand = connection.CreateCommand())
                    {
                        dcCommand.CommandText = string.Format(queryDC, ouReader.GetString(0));
                        using (IDataReader dcReader = dcCommand.ExecuteReader())
                        {
                            while (dcReader.Read())
                            {
                                domainControllers.Add(dcReader.GetString(0));
                            }
                        }
                    }
                }
            }
        }
    }


    gimme some slamming techno!!!!

    Monday, September 17, 2012 6:23 AM
    Moderator
  • Hello all ,

     Thanks for your answers, finally I am able to find out what I am looking for, We can use NetAPI32.dll as interop dll and can get the all the domain controller names in 1.1 framework. Hear is the link for that

    http://www.pinvoke.net/default.aspx/ntdsapi/DsGetDomainControllerInfo.html

    For this initially we need to get the primary domain controller and then has to pass it as a parameter.For getting the primary domain controller we need to use the following function.

    http://www.pinvoke.net/default.aspx/netapi32.NetGetDCName

    Thanks

    Kiran reddy.


    Kiran Reddy

    Tuesday, September 25, 2012 4:42 AM

All replies

  • Hi Kiran,

    Welcome to the MSDN Forum.

    As you found, the class DomainController is introduced since .net framework 2.0, so you cannot found a same one in .net 1.1. 

    So please show us which property or method you want to use, thank you.

    In addition, why do you downgrade your application, since people always upgrade it.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, September 11, 2012 8:28 AM
    Moderator
  • You need to work with DirectorySearcher class to find domain conrollers. You can read documentation at http://msdn.microsoft.com/en-us/library/9t2667d1(v=vs.71) about how to work with directory services in .NET 1.1.

    There's not much examples about subject, but there is great book The .NET Developer's Guide to Directory Services that includes both .NET 1.1 and 2.0.

    Tuesday, September 11, 2012 8:42 AM
  • Hello Mike,

     Thanks for the replay, I am looking for these 2 statements to be downgraded

    DirectoryContext dirContext = new DirectoryContext(DirectoryContextType.Domain, strDomainName);

                    DomainControllerCollection dcCollection = DomainController.FindAll(dirContext);

    And the reason for downgrade is we are having customers systems that still running on 1.1 and we are providing services for those customers as well, so we are downgrading the tools that has to supported these versions.

    Thanks

    Kiran Reddy.


    Kiran Reddy

    Wednesday, September 12, 2012 9:25 AM
  • Hi Kiran,

    How about Masasam's suggestion?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 17, 2012 2:32 AM
    Moderator
  • Use ADO.Net OleDbConnection (not sure if this is optimal)

    string logon = Environment.GetEnvironmentVariable("logonserver").TrimStart('\\');
    string queryOU = string.Format(@"<LDAP://{0}>;(&(objectCategory=organizationalUnit)(objectClass=organizationalUnit)(ou=Domain\20Controllers));distinguishedName;subTree", logon);
    string queryDC = @"<LDAP://{0}>;(objectClass=computer);distinguishedName;subTree";
    var constr = "Provider=ADsDSOObject;Encrypt Password=False;Data Source=ADs Provider;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648;";
    ArrayList domainControllers = new ArrayList();
    using (OleDbConnection connection = new OleDbConnection(constr))
    {
        connection.Open();
        using (IDbCommand ouCommand = connection.CreateCommand())
        {
            ouCommand.CommandText = queryOU;
            using (IDataReader ouReader = ouCommand.ExecuteReader())
            {
                while (ouReader.Read())
                {
                    using (IDbCommand dcCommand = connection.CreateCommand())
                    {
                        dcCommand.CommandText = string.Format(queryDC, ouReader.GetString(0));
                        using (IDataReader dcReader = dcCommand.ExecuteReader())
                        {
                            while (dcReader.Read())
                            {
                                domainControllers.Add(dcReader.GetString(0));
                            }
                        }
                    }
                }
            }
        }
    }


    gimme some slamming techno!!!!

    Monday, September 17, 2012 6:23 AM
    Moderator
  • Hello all ,

     Thanks for your answers, finally I am able to find out what I am looking for, We can use NetAPI32.dll as interop dll and can get the all the domain controller names in 1.1 framework. Hear is the link for that

    http://www.pinvoke.net/default.aspx/ntdsapi/DsGetDomainControllerInfo.html

    For this initially we need to get the primary domain controller and then has to pass it as a parameter.For getting the primary domain controller we need to use the following function.

    http://www.pinvoke.net/default.aspx/netapi32.NetGetDCName

    Thanks

    Kiran reddy.


    Kiran Reddy

    Tuesday, September 25, 2012 4:42 AM