你的位置:首页 > ASP.net教程

[ASP.net教程]C# 当前系统的多管理账户测判断


  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;          }        }