Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

  • 2 weeks later...
Posted

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

Posted

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);

}

 

 

 

}

}

 

}

  • 2 weeks later...
Posted

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.

Posted

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()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...