using (DirectoryEntry comp = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer"))
{
int AccountCount = 0;
foreach (DirectoryEntry child in comp.Children)
{
//获取账户名称
if (child.SchemaClassName == "User")
{
using (DirectoryEntry NewUser = comp.Children.Find(child.Name, "user"))
{
//判断该账户是否被禁用
bool AccountState = Convert.ToBoolean(NewUser.InvokeGet("AccountDisabled"));
if (!AccountState)
{
AccountCount += 1;
}
}
}
}
if (AccountCount > 1)
{
return 0;
}
else
{
return 1;
}
} 参考msdn:https://msdn.microsoft.com/zh-cn/library/aa746340(v=VS.85).aspx