AD ObjectCategory=Computer - How to find out if the computers are Active?

F

Fritjolf

Hi.

I'm developing a testapplication, retrieving objects of type "Computer"
from out AD server. More than 5000 are listed, and I know lots of these
are set as inactive.

I've seen some code testing if user objects are active or not:
DirectoryEntry de = searcher.FindOne().GetDirectoryEntry();
int UAC =
Convert.ToInt32(de.Properties["userAccountControl"].Value);
bool _DSEnabledAccount = (UAC &
(int)ADS_USER_FLAG.ADS_UF_ACCOUNTDISABLE) != 0;

if (_DSEnabledAccount == true)
lbxGetComputerNamePropValues.Items.Add("Computer active");
else
lbxGetComputerNamePropValues.Items.Add("Computer inactive");


I strongly believe that the value retrieved from userAccountControl is
related to users, not computers... If I run the code above ALL
computers are listed as inactive.

Has anyone coded something around computer objects and checked if the
computer objects are active?

Help is greatly appreciated.

Fritjolf
 
W

Willy Denoyette [MVP]

See inline.

Willy.

| Hi.
|
| I'm developing a testapplication, retrieving objects of type "Computer"
| from out AD server. More than 5000 are listed, and I know lots of these
| are set as inactive.
|
| I've seen some code testing if user objects are active or not:
| DirectoryEntry de = searcher.FindOne().GetDirectoryEntry();
| int UAC =
| Convert.ToInt32(de.Properties["userAccountControl"].Value);
| bool _DSEnabledAccount = (UAC &
| (int)ADS_USER_FLAG.ADS_UF_ACCOUNTDISABLE) != 0;
|
| if (_DSEnabledAccount == true)
| lbxGetComputerNamePropValues.Items.Add("Computer active");
| else
| lbxGetComputerNamePropValues.Items.Add("Computer inactive");
|
|

There is a bug in this code: true is returned when
ADS_USER_FLAG.ADS_UF_ACCOUNTDISABLE is set in UAC, that means that true
means DISABLED.
Note that this doesn't mean that the machine (or whetever) account is
active, it only means that he is enabled. He may even be non existant.



| I strongly believe that the value retrieved from userAccountControl is
| related to users, not computers... If I run the code above ALL
| computers are listed as inactive.
|
userAccountControl is for users as well as for computers.


| Has anyone coded something around computer objects and checked if the
| computer objects are active?
|
| Help is greatly appreciated.
|
| Fritjolf
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top