Dieser Code (mit Beispiel für den Aufruf) fügt einen Domainen-Account zu einer Localen Gruppe hinzu.
'Hier der Code
Public Function AddDoaminUserToGroup(ByVal LocalSystemName As String, _
ByVal DOMAIN As String, _
ByVal DomainUserName As String, _
ByVal AddToLocalGroup As String) As Boolean
Try
Dim LocalSystem As New DirectoryEntry("WinNT://" & LocalSystemName & ",computer")
Dim DomainName As New DirectoryEntry("WinNT://" & DOMAIN)
Dim DOMUSR As DirectoryEntry = DomainName.Children.Find(DomainUserName, "user")
Dim LocalGroup As DirectoryEntry = LocalSystem.Children.Find("Test", "group")
LocalGroup.Invoke("Add", New Object() {DOMUSR.Path.ToString})
Return True
Catch ex As Exception
Return False
End Try
End Function
'So der Aufruf
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("Operation successfull: " & _
AddDoaminUserToGroup(System.Environment.MachineName, _
"Domain1", _
"DomainUser1", _
"LocaleGruppe"), "Adding Domain User", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
1 Kommentare zum Snippet