lmwinbur Posted January 7, 2004 Posted January 7, 2004 Is there a place in the .Net framework for user management similar to the "Active DS Type Library" com object? I would like to keep all my code in the .Net framework if possible. Thanks, Landon. Quote
Administrators PlausiblyDamp Posted January 7, 2004 Administrators Posted January 7, 2004 System.DirectoryServices Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
lmwinbur Posted January 7, 2004 Author Posted January 7, 2004 Thanks, thats what I was looking for... Unfortunately the msdn doesn't really have any good examples of this in VB or using local groups. I need to remove all the users from a local group and add one or more back. I took some samples I found and this is as far as I got. This isn't working for me either. I'm not sure where to go from here. Dim usr As New System.DirectoryServices.DirectoryEntry() usr.Path = "WinNT://MachineName/user" Dim group As New System.DirectoryServices.DirectoryEntry() group.Path = "WinNT://MachineName/test" group.Properties("member").Add(usr.Properties("distinguishedName").Value) group.CommitChanges() Thanks, Landon. Quote
lmwinbur Posted January 7, 2004 Author Posted January 7, 2004 I have all of the system.directoryservices stuff working except enumerating the groups members. Every example I have found have used the iadsmembers to invoke the members of a group. I was trying not to reference the activeds type library. Anyone know of a way to enumerate the group without using activeds? This is the code that is currently working with activeds. Dim Comp As New DirectoryEntry("WinNT://" & Environment.MachineName & ",computer") Dim Group As New DirectoryEntry("WinNT://" & Environment.MachineName & "/test") 'Comp.Children.Find("test", "group") Dim Members As ActiveDs.IADsMembers = Group.Invoke("members") Dim filter As Object = "user" Members.Filter = filter Dim member As IADsUser For Each member In Members Group.Invoke("Remove", member.ADsPath) Next If Not (Group.Name Is Nothing) Then Group.Invoke("Add", New [Object]() {"WinNT://" & Environment.MachineName & "/username"}) End If Thanks, Landon. Quote
trollibus Posted January 20, 2004 Posted January 20, 2004 hi, i've found some samples in c# but i would have like to do that in vB.net... I just like to list all the groups of the domain and for each groups, to list the user... thx, troll Quote
lmwinbur Posted January 20, 2004 Author Posted January 20, 2004 Can you post the C# code? I'd like to run it through the CStoVB converter and see if it does what I'm looking for. Thanks, Landon. Quote
trollibus Posted January 21, 2004 Posted January 21, 2004 Based on what i found on those sites: http://www.dotnet247.com/247reference/msgs/37/189402.aspx http://www.dotnet247.com/247reference/msgs/27/136289.aspx http://www.codeproject.com/dotnet/addnewuser.asp?print=true But those sample are all using ACTIVEDS I hope being able to send a complete code without ACTIVEDS tomorow.. Quote
trollibus Posted January 21, 2004 Posted January 21, 2004 here a sample without ACTIVEDS. You have to specify the the computername in the code and it give the user and the group. That's not really what i want but it works. It's also is a c# console: using System; using System.DirectoryServices; using System.Runtime.InteropServices; using System.Reflection; namespace console_test_group { /// <summary> /// Summary description for Class1. /// </summary> class Test { public static void Main() { System.DirectoryServices.DirectoryEntry entryRoot = new System.DirectoryServices.DirectoryEntry ("WinNT://PEI-VMWARE", null, null, AuthenticationTypes.None ); try { System.DirectoryServices.DirectoryEntries memberEntries = entryRoot.Children; foreach (System.DirectoryServices.DirectoryEntry member in memberEntries) { if (member.SchemaClassName.Equals("User")) Console.WriteLine("USER: " + member.Name); if (member.SchemaClassName.Equals("Group")) Console.WriteLine("GROUP: " + member.Name); } } catch (System.Runtime.InteropServices.COMException e) { Console.WriteLine ( "Error " + e); } } } } Quote
trollibus Posted January 21, 2004 Posted January 21, 2004 global group <> local group Could you tell me how i can make the distinction through local group and global group in my domain ? thx, Pat Quote
lmwinbur Posted January 29, 2004 Author Posted January 29, 2004 Looks like it successfully listed all users and groups of the local computer. Do you know how to list the users in a specific group without activeds? Landon. Quote
lmwinbur Posted January 29, 2004 Author Posted January 29, 2004 Aaarrrgghhh.... This is so frusterating... I found some code that enumerates a local group without activeds and it works great, problem is that it doesn't run when put into the onshutdown() method of a service. I get the following error when trying to invoke the members of the group. This operation is only allowed on the primary domain controller of the domain It works fine in the onstop() method when I stop the service manually. I have the service running under the system account and I have it depending everything I can think of (Workstation, Server, Computer Browser, and Net Logon). Here is the code that is running. Any help would be appreciated... Thanks, Landon. Try f = IO.File.CreateText("c:\test.txt") f.WriteLine("Connecting") Dim localGroup As New DirectoryEntry("WinNT://machinename/test,group") f.WriteLine("Getting members") Dim allMembers As Object = localGroup.Invoke("Members") Dim groupMember As Object f.WriteLine("Enum") For Each groupMember In CType(allMembers, IEnumerable) Dim member As New DirectoryEntry(groupMember) f.WriteLine("Removing") localGroup.Invoke("Remove", member.Path) Next Catch f.WriteLine(Err.Description) End Try f.Flush() f.Close() Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.