You are hereVB.Net - How to Disable a Domain Account in Active Directory
VB.Net - How to Disable a Domain Account in Active Directory
How to Disable a Domain Account in Active Directory utilizing Visual Basic .Net - (note: you must have Domain Admin privledges to execute this code successfully and you must import the System.DirectoryServices namespace):
Dim strError As String
Try
Dim child As New System.DirectoryServices.DirectoryEntry("LDAP://DC=YourDomainsName,DC=com")
Dim searcher As New DirectorySearcher(child)
Dim result As SearchResult
Dim userEntry As DirectoryEntry
searcher.Filter = "(SAMAccountName=TheUsernameYouWantDisabled)"
searcher.CacheResults = False
result = searcher.FindOne
userEntry = result.GetDirectoryEntry
With userEntry
userEntry.NativeObject.accountdisabled = True
End With
userEntry.CommitChanges()
Catch ex As Exception
strError = ex.ToString
End Try
End Sub