Verify Network User Account isnt locked out.

G

Guest

On occasion a Network User Account gets locked out. This causes lots of
problems as the account is used to run different programs. The programs fail
when the user account is locked out.
I would like to write a c# program that will check if the Network User
Account is locked out?
Can someone point me in the right direction? An API?

TIA,
Vinny
 
W

Willy Denoyette [MVP]

Vinny Vinn said:
On occasion a Network User Account gets locked out. This causes lots of
problems as the account is used to run different programs. The programs
fail
when the user account is locked out.
I would like to write a c# program that will check if the Network User
Account is locked out?
Can someone point me in the right direction? An API?

TIA,
Vinny

You have at least two options:

1. You can use DirectoryServices and check the LOCKOUT bit in the
"userAccountControl" property of the AD user object.

const int ADS_UF_LOCKOUT = 0x00000010;
using(DirectoryEntry user = new
DirectoryEntry("LDAP://..../CN=userAcc0,DC=..,DC=..,DC=..", ...))
{
if (((int)user.Properties["userAccountControl"].Value &
ADS_UF_LOCKOUT) == 1)
{
Console.WriteLine("Account locked");
}
}
}

2. You can call LogonUser and check the return value and Win32 error code.

Willy.
 

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