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;
                                }
                            }
                        }
                    }
                    if (AccountCount > 1)
                    {
                        return 0;
                    }
                    else
                    {
                        return 1;
                    }
                }

参考msdn:https://msdn.microsoft.com/zh-cn/library/aa746340(v=VS.85).aspx

  

posted @ 2016-05-13 14:00  Shen_小沈  阅读(499)  评论(0编辑  收藏  举报