User management with the framework?

lmwinbur

Member
Joined
Jan 6, 2004
Messages
7
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.
 
Thanks, thats what I was looking for...

Unfortunately the msdn doesnt 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 isnt working for me either. Im 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.
 
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.
 
hi,
ive 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
 
Can you post the C# code? Id like to run it through the CStoVB converter and see if it does what Im looking for.

Thanks,
Landon.
 
here a sample without ACTIVEDS.
You have to specify the the computername in the code and it give the user and the group.
Thats not really what i want but it works.
Its 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);
}



}
}

}
 
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
 
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.
 
Aaarrrgghhh.... This is so frusterating... I found some code that enumerates a local group without activeds and it works great, problem is that it doesnt 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()
 
Back
Top