Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Adding Active Directory Users to local Groups

Adding Active Directory Users to local Groups

Scheduled Pinned Locked Moved C#
comwindows-admin
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andre Stroebel
    wrote on last edited by
    #1

    I am trying to add a AD user to a local group, but keep on getting an exception: ex Message - Exception has been thrown by the target of an invocation. ex InnerException - An invalid directory pathname was passed DirectoryEntry activeDirectory = new DirectoryEntry("LDAP://DomainName.com", LoggedOnUser, LoggedOnPassword); DirectorySearcher dsUsers = new DirectorySearcher(activeDirectory); dsUsers.Filter = "samaccountname=" + userName; SearchResult srCheckUser; if ((srCheckUser = dsUsers.FindOne()) != null) { //User Found. DirectoryEntry newUser = srCheckUser.GetDirectoryEntry(); //Set up currentGroup...... currentGroup.Invoke("Add", new object[] { newUser.Path.ToString() }); }

    A 1 Reply Last reply
    0
    • A Andre Stroebel

      I am trying to add a AD user to a local group, but keep on getting an exception: ex Message - Exception has been thrown by the target of an invocation. ex InnerException - An invalid directory pathname was passed DirectoryEntry activeDirectory = new DirectoryEntry("LDAP://DomainName.com", LoggedOnUser, LoggedOnPassword); DirectorySearcher dsUsers = new DirectorySearcher(activeDirectory); dsUsers.Filter = "samaccountname=" + userName; SearchResult srCheckUser; if ((srCheckUser = dsUsers.FindOne()) != null) { //User Found. DirectoryEntry newUser = srCheckUser.GetDirectoryEntry(); //Set up currentGroup...... currentGroup.Invoke("Add", new object[] { newUser.Path.ToString() }); }

      A Offline
      A Offline
      Andre Stroebel
      wrote on last edited by
      #2

      If you ever stumble across this problem... http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1008.mspx Used LDAP to browse AD. Turns out if you want to add a AD User to a local Group you should use WinNT connection strings. :wtf:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups