-
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
-
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!
-
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 04:11 PM.
-
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!
-
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)
-
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!
-
That's more like it, I'll dig into that.
Thanks again.
Similar Threads
-
By Adriano Fabri in forum .NET
Replies: 0
Last Post: 04-04-2003, 10:59 AM
-
Replies: 1
Last Post: 12-02-2002, 04:09 PM
-
By Chris Schrumm in forum .NET
Replies: 1
Last Post: 08-12-2002, 10: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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks