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; } //var state = NewUser.Properties["UserFlags"].Value.ToString(); //if (state == "66049" || state == "66145") //{ // AccountCount += 1; //} } } } if (AccountCount > 1) { return 0; } else { return 1; } }
原标题:C# 当前系统的多管理账户测判断
关键词:C#