我怎样才能得到一个列表的本地Windows用户(仅出现在Windows登录屏幕的用户) [英] How can I get a list Local Windows Users (Only the Users that appear in the windows Logon Screen)

查看:295
本文介绍了我怎样才能得到一个列表的本地Windows用户(仅出现在Windows登录屏幕的用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能获得本地Windows用户(仅出现在Windows登录屏幕的用户)的列表

How can I get a list of Local Windows Users (Only the Users that appear in the windows Logon Screen)

我曾尝试使用Windows原理库和许多方法放大器; WMI选择命令。我不断收到管理员,客户和放大器;其他一些奇怪的帐户(VUSRNEIL-DELL,$ HOMEGROUPUSER,ASPNET ...等)

I have tried many methods using Windows Principle library & WMI Select commands. I keep getting Administrator, Guest & some other bizarre accounts (VUSRNEIL-DELL, $HOMEGROUPUSER, ASPNET...etc.)

无论这3个用户帐户出现在登录屏幕上。我如何可以将这些用户类型区分?

Neither of these 3 user accounts appear on the Logon screen. How can I Differentiate between these user types?

我编码在C#

推荐答案

只需添加一个控制台应用程序的引用 System.Management 并尝试这段代码:

Just add a reference to System.Management in a Console Application and try this code:

using System;
using System.Management;
using System.Linq;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementObjectSearcher usersSearcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_UserAccount");
            ManagementObjectCollection users = usersSearcher.Get();

            var localUsers = users.Cast<ManagementObject>().Where(
                u => (bool)u["LocalAccount"] == true &&
                     (bool)u["Disabled"] == false &&
                     (bool)u["Lockout"] == false &&
                     int.Parse(u["SIDType"].ToString()) == 1 &&
                     u["Name"].ToString() != "HomeGroupUser$");

            foreach (ManagementObject user in users)
            {
                Console.WriteLine("Account Type: " + user["AccountType"].ToString());
                Console.WriteLine("Caption: " + user["Caption"].ToString());
                Console.WriteLine("Description: " + user["Description"].ToString());
                Console.WriteLine("Disabled: " + user["Disabled"].ToString());
                Console.WriteLine("Domain: " + user["Domain"].ToString());
                Console.WriteLine("Full Name: " + user["FullName"].ToString());
                Console.WriteLine("Local Account: " + user["LocalAccount"].ToString());
                Console.WriteLine("Lockout: " + user["Lockout"].ToString());
                Console.WriteLine("Name: " + user["Name"].ToString());
                Console.WriteLine("Password Changeable: " + user["PasswordChangeable"].ToString());
                Console.WriteLine("Password Expires: " + user["PasswordExpires"].ToString());
                Console.WriteLine("Password Required: " + user["PasswordRequired"].ToString());
                Console.WriteLine("SID: " + user["SID"].ToString());
                Console.WriteLine("SID Type: " + user["SIDType"].ToString());
                Console.WriteLine("Status: " + user["Status"].ToString());
            }

            Console.ReadKey();
        }
    }
}

这篇关于我怎样才能得到一个列表的本地Windows用户(仅出现在Windows登录屏幕的用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆