title: how to delete computer account from Active Directory using c#
body: <p>Is there any sample that deletes computer account from AD using C#? </p>
  
  <p>I have searched many sources, but all are about user account.</p>
  
  <p>added my code here, i always got errors for some reason.</p>
  
  <pre><code>public static bool checkExistingPC(string compName,string userName,string userPwd )
  {
      try
      {
          DirectoryEntry entry = new DirectoryEntry("LDAP://test.com",userName,userPwd,AuthenticationTypes.Secure);
          DirectorySearcher mySearcher = new DirectorySearcher(entry);
         mySearcher.Filter = "(&amp;(objectClass=computer)(|(cn=" + compName + ")(dn=" + compName + ")))";
         foreach (SearchResult result in mySearcher.FindAll())
         {
             if (result != null)
             {
  
                 MessageBox.Show("computer GetDirectoryEntry():" + result.Path+"\n"+"computer path: "+result.Path);
                  DirectoryEntry entryToRemove = new DirectoryEntry(result.Path,userName,userPwd);
                   entry.Children.Remove(entryToRemove);
  
                 return true;
             }
             else
             {
                 return false;
             }
         }
      }
      catch (Exception e)
      {
          MessageBox.Show(e.Message);
      }
      return false;
  }
  </code></pre>