I have a VB.net class (asp.net project) for managing local user accounts.
I support more than 200 servers across north america that are not in a domain (long story).
My has no issue adding users, setting passwords and even creating groups, but I cant figure out how to add users to a group.
Here is the add user function - properties are used for gathering information - this works well
Public Function AddUser()
Dim obDirEntry As DirectoryEntry = Nothing
Try
obDirEntry = New DirectoryEntry("WinNT://" & pServer)
Dim entries As DirectoryEntries = obDirEntry.Children
Dim obUser As DirectoryEntry = entries.Add(pUserName, "User")
obUser.Properties("FullName").Add(pFullName)
obUser.Properties("Description").Add(pDescription)
Dim obRet As Object = obUser.Invoke("SetPassword", pPassword)
obUser.CommitChanges()
obDirEntry.Close()
Return True
Catch ex As Exception
Return ex.Message
End Try
End Function
Here is my function for adding a user to a group - The msgboxes are there to gather error info
Public Function AddToGroup()
Try
Dim obDirEntry As New DirectoryEntry("WinNT://" & pServer & ",computer")
Dim obUser As DirectoryEntry = obDirEntry.Children.Find(pUserName, "user")
Dim obGroup As DirectoryEntry = obDirEntry.Children.Find("Administrators", "group")
obGroup.Invoke("Add", New Object() {obUser.Path.ToString})
obGroup.CommitChanges()
obDirEntry.Close()
Return True
Catch ex As Exception
MsgBox(ex.Message)
MsgBox(ex.InnerException.Message)
Return False
End Try
End Function
Here are the two errors
1) Exception has been thrown by the target of an invocation.
2) A memeber could not be added to or removed from the local group because the member does not exist
I have also added to other msgbox's to look at the paths returned and this is the results
obdirentry = WinNT://10.106.3.220,computer
obUser = WinNT://workgroup/10.106.3.220/test88 ------
test88 is a valid user on the target system
Any help would be great... Thanks in advance