Create System User by .NET

Imports System.DirectoryServices

Dim AD As New DirectoryEntry("WinNT://" & Environment.MachineName + ",computer")

Dim NewUser As DirectoryEntry = AD.Children.Add("rachit", "user")

NewUser.Invoke("SetPassword", New Object() {"rachit"})

NewUser.Invoke("Put", New Object() {"Description", "Created by Rachit."})

NewUser.CommitChanges()

NewUser.RefreshCache()

Dim grp As DirectoryEntry

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

If grp IsNot Nothing Then

grp.Invoke("Add", New Object() {NewUser.Path.ToString()})

End If

Ebook Download
View all
Learn
View all