vb.net problems accessing Active Directory and DirectoryServices namespace


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: vb.net problems accessing Active Directory and DirectoryServices namespace

  1. #1
    Join Date
    Dec 2004
    Posts
    24

    vb.net problems accessing Active Directory and DirectoryServices namespace

    (see bottom for a working vbscript code snippet of what I want to do - dump all of the groups a user is in)

    My problem is twofold.
    First, I can't reference the system.directoryServices namespace at all.
    I'm using visual studio 2003, .net framework 1.1

    I can't seem to get to the any of the classes in the directoryServices namespace described here on MSN:
    "The System.DirectoryServices namespace provides easy access to Active Directory from managed code. The namespace contains two component classes, DirectoryEntry and DirectorySearcher, which use the Active Directory Services Interfaces (ADSI) technology. ADSI is the set of interfaces that Microsoft provides as a flexible tool for working with a variety of network providers. ADSI gives the administrator the ability to locate and manage resources on a network with relative ease, regardless of the network's size."

    If I try to declare a variable as an instance of one of the classes, there is nothing to choose from on the drop-down (it goes from Diagnostics to DivideByZeroException). Same if I try to add an Imports on the top of my code.



    This works assuming domain and logonId are populated.

    dom = domain & "/"
    dim grp,grplist,usr, logonId

    Set UserObj = GetObject("WinNT://" & dom & loginID & ",user")

    for each grp in UserObj.Groups
    WScript.Echo grp.name
    next

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Sounds like you need to add a reference in your project to System.DirectoryServices.dll: From VS.NET's Project menu, select Add Reference... In the resulting dialog, select System.DirectoryServices.dll and click OK. You should then be able to use the namespace from your code.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Dec 2004
    Posts
    24
    Yes that did work, thank you (I thought I tried to add a reference to it before but didn't see it).

    Do you have ANY heavenly idea how to translate that vbscript code to vb.net?
    It is very simple (vbscript-wise) and I'd hate to think they made it difficult in .net but after pouring over the .net documentation regarding active directory, I'm still in the dark.
    It simply dumps the groups a user is a member of.
    Last edited by ToddT; 09-06-2005 at 05:11 PM.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Look at the section titled, "Obtaining Group Membership for a User" on this page: http://www.wwwcoder.com/main/parentid/260/site/2150/68/ . I found it by Googling for "vb.net system.directoryservices group membership".
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Dec 2004
    Posts
    24
    I get a page not found on that.
    I'll try that same search and see if I can find what you found.

    I just got back from a search on "group membership active directory .net" with no real concrete results.

    (edit - actually I had a hit on my search on that same site, different thread)

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    Dec 2004
    Posts
    24
    That's more like it, I'll dig into that.
    Thanks again.

Similar Threads

  1. View all user of Active Directory.
    By Adriano Fabri in forum .NET
    Replies: 0
    Last Post: 04-04-2003, 11:59 AM
  2. Active Directory problems
    By Brian S in forum .NET
    Replies: 1
    Last Post: 12-02-2002, 05:09 PM
  3. Active Directory .Net and Browsing the directory
    By Chris Schrumm in forum .NET
    Replies: 1
    Last Post: 08-12-2002, 11:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center