I use a TADOQuery instead of a TADOCommand, adding a calculated TStringField (CalcUserAccountControl) of length 200, and declaring the following type and constants:
(you can check the values of every flag at UserAccountControl property flags)
type
TControlFlags = ( SCRIPT, ACCOUNTDISABLE, HOMEDIR_REQUIRED, LOCKOUT, PASSWD_NOTREQD,
PASSWD_CANT_CHANGE, ENCRYPTED_TEXT_PWD_ALLOWED, TEMP_DUPLICATE_ACCOUNT,
NORMAL_ACCOUNT, INTERDOMAIN_TRUST_ACCOUNT, WORKSTATION_TRUST_ACCOUNT,
SERVER_TRUST_ACCOUNT, DONT_EXPIRE_PASSWORD, MNS_LOGON_ACCOUNT,
SMARTCARD_REQUIRED, TRUSTED_FOR_DELEGATION, NOT_DELEGATED,
USE_DES_KEY_ONLY, DONT_REQ_PREAUTH, PASSWORD_EXPIRED,
TRUSTED_TO_AUTH_FOR_DELEGATION, PARTIAL_SECRETS_ACCOUNT);
...
const
//Bit position of every flag
BitControlFlag : Array [TControlFlags] of Integer =
(0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26);
//Description of every flag
StrControlFlag : Array [TControlFlags] of string =
('|SCRIPT', '|ACCOUNTDISABLE', '|HOMEDIR_REQUIRED', '|LOCKOUT', '|PASSWD_NOTREQD',
'|PASSWD_CANT_CHANGE', '|ENCRYPTED_TEXT_PWD_ALLOWED', '|TEMP_DUPLICATE_ACCOUNT',
'|NORMAL_ACCOUNT', '|INTERDOMAIN_TRUST_ACCOUNT', '|WORKSTATION_TRUST_ACCOUNT',
'|SERVER_TRUST_ACCOUNT', '|DONT_EXPIRE_PASSWORD', '|MNS_LOGON_ACCOUNT',
'|SMARTCARD_REQUIRED', '|TRUSTED_FOR_DELEGATION', '|NOT_DELEGATED',
'|USE_DES_KEY_ONLY', '|DONT_REQ_PREAUTH', '|PASSWORD_EXPIRED',
'|TRUSTED_TO_AUTH_FOR_DELEGATION', '|PARTIAL_SECRETS_ACCOUNT');
...
After that, at the OnCalcFields method of the TADOQuery, just check the bit at the UserAccountControl field from the query,
procedure TForm2.TADOQuery1CalcFields(DataSet: TDataSet);
var
CurrentUAC : Integer;
StrUAC : String;
ControlFlags : TControlFlags;
begin
CurrentUAC := TADOQuery1.FieldByName('userAccountControl').AsInteger;
for var aControlFlag := low(ControlFlags) to high(ControlFlags) do
if CurrentUAC and (1 shl BitControlFlag[aControlFlag]) <> 0 then
strUAC := strUAC + StrControlFlag[aControlFlag];
TADOQuery1.FieldByName('CalcUserAccountControl').Value := strUAC;
end;
At the calculated fiel I got a string with every flag of the UserAccountControl, something like:
|PASSWD_NOTREQD|WORKSTATION_TRUST_ACCOUNT
|WORKSTATION_TRUST_ACCOUNT|DONT_EXPIRE_PASSWORD
|ACCOUNTDISABLE|PASSWD_NOTREQD|WORKSTATION_TRUST_ACCOUNT
With that in mind you can use the CalculatedField value in order to filter the result set to show only those UserAccountControl flags you require.