LDAP Statement to Disable Computer Account

Last post 11-08-2007 9:40 PM by gsdtech. 1 replies.

Sort Posts:

  • LDAP Statement to Disable Computer Account

    11-08-2007, 7:06 PM
    • Loading...
    • tbraga
    • Joined on 10-16-2007, 11:18 PM
    • Posts 132

    Hi All,

    I'm fairly new to LDAP query's.  Can anyone tell me how to disable (not delete) a computer account in Active Directory.  I have searched the web for a couple hours and have tried different things on my own but can't get it to run.  I'm using VB.net behind my ASP.net. 

    Anything will be helpful,
    Thanks in advance!
    Tim

    Filed under: , ,
  • Re: LDAP Statement to Disable Computer Account

    11-08-2007, 9:40 PM
    Answer
    • Loading...
    • gsdtech
    • Joined on 12-21-2006, 4:36 PM
    • Kennewick, WA
    • Posts 53

    Here's some code that should get you started. The original C# code is from http://www.dotnettreats.com/tipstricks/adnet.aspx#s11 and was converted to VB.NET using http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx.

      

    Public Sub DisableAccount(ByVal EmployeeID As String) 
        Dim de As DirectoryEntry = GetDirectoryEntry() 
        Dim ds As New DirectorySearcher(de) 
        ds.Filter = "(&(objectCategory=Person)(objectClass=user)(employeeID=" + EmployeeID + "))" 
        ds.SearchScope = SearchScope.Subtree 
        Dim results As SearchResult = ds.FindOne() 
        
        If results IsNot Nothing Then 
            Dim dey As DirectoryEntry = GetDirectoryEntry(results.Path) 
            Dim val As Integer = CInt(dey.Properties("userAccountControl").Value) 
            dey.Properties("userAccountControl").Value = val Or 2 
            dey.Properties("msExchHideFromAddressLists").Value = "TRUE" 
            dey.CommitChanges() 
            dey.Close() 
        End If 
        
        de.Close() 
    End Sub 
     
    "Peace is Every Step." -Thich Nhat Hanh
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter