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

  • SEARCH
  • Home
  • 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 6383205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:37:12+00:00 2026-05-25T02:37:12+00:00

I need to refactor a VBS dealing with LDAP, ADODB and ActiveDirectory from VBS

  • 0

I need to refactor a VBS dealing with LDAP, ADODB and ActiveDirectory from VBS to C#. The part I’m stuck is connecting (just starting and already stuck… great). This is the original source

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfig = objRootDSE.Get("configurationNamingContext")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"

adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

strQuery = "<LDAP://dm1.com.local/OU=CN,OU=Users,OU=CMS Organizational,OU=CMS_Users_and_Groups,DC=cms,DC=local>;(&(objectCategory=person)(objectClass=user)(!useraccountcontrol:1.2.840.113556.1.4.803:=2));distinguishedName,lastLogon,whenCreated;subtree"

adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 60
adoCommand.Properties("Cache Results") = False

Set adoRecordset = adoCommand.Execute

And the C# looks like this

DirectoryEntry dse = new DirectoryEntry("LDAP://RootDSE");
string config = dse.Properties["configurationNamingContext"].Value.ToString();
string domain = dse.Properties["defaultNamingContext"].Value.ToString();
Connection connection = new Connection();
connection.Provider = "ADsDSOObject";
connection.Open("ADsDSOObject", "", "", 0);

object records, parameters = "";

ADODB.Command command = new Command();
command.ActiveConnection = connection;
command.CommandText = "<LDAP://dm1.com.local/OU=CN,OU=Users,OU=CMS Organizational,OU=CMS_Users_and_Groups,DC=cms,DC=local>;(&(objectCategory=person)(objectClass=user)(!useraccountcontrol:1.2.840.113556.1.4.803:=2));distinguishedName,lastLogon,whenCreated;subtree";
command.Execute(out records, ref parameters, 0);

It gives me the error

Interface not supported (Provider)
 at ADODB.CommandClass.Execute(Object& RecordsAffected, Object& Parameters, Int32 Options)
at Adug.Program.Main(String[] args) in E:\...\Program.cs:line 66
  • 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-05-25T02:37:12+00:00Added an answer on May 25, 2026 at 2:37 am

    I have no experience with querying LDAP via ADO, but I have used the following code successfully (simplified here), which makes use of DirectorySearcher:

    DirectoryEntry directoryEntry = new DirectoryEntry(
          config.DirectoryConnectionString, 
          config.ActiveDirectoryUserName, 
          config.GetPassword(), 
          AuthenticationTypes.Secure);
    DirectorySearcher ds = new DirectorySearcher(directoryEntry);
    
    ds.PropertiesToLoad.Add("cn");
    ds.PropertiesToLoad.Add("sAMAccountName");
    ds.PropertiesToLoad.Add("mail");
    ds.PropertiesToLoad.Add("displayName");
    
    ds.Filter = "(objectClass=user)";
    
    foreach (SearchResult result in ds.FindAll())
    {
        string displayName = String.Empty;
        DirectoryEntry entry = result.GetDirectoryEntry();
        if (entry.Properties.Contains("displayName"))
                if (entry.Properties["displayName"].Count > 0)
                    displayName  = entry.Properties["displayName"][0].ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just embarking on my first large-scale refactor, and need to split an
I need to refactor existing code by collapsing a method that's copy-and-pasted between various
I need to refactor my project in order to make it immune to OutOfMemory
I am probably going to need to refactor in two steps since I'm still
I have an old untyped class pre Java1.5 and need to refactor it using
Edit: I need to refactor this question, it has too many extraneous components to
I need to refactor this code to not use a parameter when using the
I feel the need to refactor my old CF5 based code into CFC's. We
I have a number of collections of classes which I need to refactor into
I've got some sample code that I'd like to refactor as I need it

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.