Listing 1: Excerpt from the listStaleAccounts Function connection = new ActiveXObject("ADODB.Connection"); connection.Open("Provider=ADSDSOObject;"); command = new ActiveXObject("ADODB.Command"); command.ActiveConnection = connection; command.Properties("Cache results") = false; command.Properties("Page size") = 1000; command.Properties("Timeout") = 60; command.Properties("Sort on") = "CN"; // The CommandText property contains // the LDAP query. Note that // "!(userAccountControl:1.2.840.113556.1.4.803:=2)" // includes only enabled accounts. command.CommandText = ";" + "(&" + (computers ? "(objectClass=computer)" : "(objectCategory=person)(objectClass=user)") + "(!(userAccountControl:1.2.840.113556.1.4.803:=2))" + (expiredPwds ? "" : "(!(pwdLastSet=0))") + ");distinguishedName,sAMAccountName,userAccountControl;" + (recurse ? "subtree" : "onelevel");