views:

259

answers:

0

I am trying to do the same thing in vb.net as the op in this post see below

but I would like to do it using System.directoryservices method just like he mentioned later in the post.

i don't see why i can't since I am able to add a user to the admin group using DS method.

ex.

    Public Shared Sub AddAdminAccount(ByVal username As String, ByVal PCname As String)
    Try
        If UserFuncLib.UserExists(username) Then
            If UserFuncLib.GetUserInfo(username) Then
                'Bind and get the local directory container of the administator group'
                Dim grp As DirectoryServices.DirectoryEntry
                grp = DirEntrylib.getDirEntry()
                grp.Path = "WinNT://" & PCname & "/Administrators,group"

                Try
                    ' Add user to administrators alias'
                    grp.Invoke("Add", "WinNT://" & DirEntrylib.SelectedDomain & "/" & username & ",user")
                    grp.CommitChanges()
                Catch ex As System.Reflection.TargetInvocationException
                    Console.WriteLine(ex.InnerException.Message)
                Catch ex As Exception
                    Console.WriteLine(((ex.Message & vbLf) + ex.StackTrace & vbLf) + ex.Source)
                End Try
            Else
                'do stuff here'
            End If
        Else
            'do stuff here'
        End If
    Catch ex As Exception
        Console.WriteLine(((ex.Message & vbLf) + ex.StackTrace & vbLf) + ex.Source)
    End Try
End Sub

Any ideas?

DS method