사용자 계정 추가
*
Imports System.DirectoryServices
Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
Dim dirEntry As DirectoryEntry
dirEntry = New DirectoryEntry("WinNT://" + Environment.MachineName + ",computer")
Dim entries As DirectoryEntries = dirEntry.Children
' Set login name and full name.
Dim newUser As DirectoryEntry = entries.Add(TextBoxID.Text, "User")
newUser.Properties("FullName").Add(TextBoxFullname.Text)
newUser.Properties("HomeDirectory").Add("C:\")
newUser.Properties("Description").Add("Member of site.")
' User must change password at next logon (1 - true, 0 - false)
newUser.Properties("PasswordExpired").Add(0)
' Password never expires.
'newUser.Properties("PasswordAge").Add(0)
' Set flags - User Cannot change password | Password never expires.
newUser.Properties("Userflags").Add(&H40 Or &H10000)
' Set the password.
Dim result As Object = newUser.Invoke("SetPassword", TextBoxPass.Text)
newUser.CommitChanges()
' Add user to the group "Members"
Dim grp As DirectoryEntry = dirEntry.Children.Find(TextBoxGroup.Text, "group")
If (Not grp Is Nothing) Then
grp.Invoke("Add", New Object() {newUser.Path.ToString()})
MsgBox("New User Account Created")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

add.PNG

 

add2.PNG

 

참조를 System.DirectoryServices.dll 어셈블리에 추가

 

이 게시물을

공유하기

SEARCH

MENU NAVIGATION