Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
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
            'Trace.Warn(ex.Message)
            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

VB
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
Posted

1 solution

Any thoughts on this one... If someone has a different way of doing this in VB.net I am open to that aswell
 
Share this answer
 
Comments
d_modugno 25-Oct-13 11:09am    
I could really use some help here.... someone must have done this before
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900