Add Active Directory Users to a Group on a Workstation

  • Thread starter Thread starter whoopes
  • Start date Start date
Then I don't understand. The MS example should work for you locally.
what happens when you try?
 
THe following is my code which doesn't work:

Sub Main()
Dim AD As DirectoryEntry = New DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer")
Dim grp As DirectoryEntry

grp = AD.Children.Find("Administrators", "group")

If grp.Name <> "" Then
Console.WriteLine("Going to add to group")
grp.Invoke("Add", New Object() {"<domain>\<user>"})
Else
Console.WriteLine("Group does not exist")
End If
End Sub

Debugging says: System.Reflection.TargetInvocationException was
unhandled

Thanks for working with me!
 
Dump just meant that I am trying to keep the post alive, hoping someone
else may see it.
It's erroring out at grp.Invoke("Add", New Object()
{"<domain>\<user>"})

://Bill
 
Figured it out. Should be:

Dim StrUserEntry As String
StrUserEntry = "WinNT://<domain>/<server>/<userid>"

Dim group As DirectoryEntry = New DirectoryEntry("WinNT://" +
Environment.MachineName + "/Administrators,group")

group.Invoke("Add", New Object() {StrUserEntry})
group.CommitChanges()
 
Back
Top