How can I get a list of Local Windows Users (Only the Users that appear in the windows Logon Screen)
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.)
Neither of these 3 user accounts appear on the Logon screen. How can I Differentiate between these user types?
I am coding in C#
If you're using WMI to query
Win32_UserAccount
you can display only items that meet following conditions:AccountType
has theUF_NORMAL_ACCOUNT
flag.Disabled
isfalse
.Lockout
isfalse
.LocalAccount
istrue
.SIDType
isSidTypeUser
.If you can't use WMI (or you do not want to use it) then you have to do a little bit more work, basically you have to use NetGroupGetUsers function to enumerate all users. See this article on CodeProject for an example.
If you want to use a wrappered solution, NuGet has the "Continuous.Management" package - which is an open source project: https://github.com/jarzynam/continuous
Just add a reference to
System.Management
in a Console Application and try this code:This will give you a list of all user accounts, their domain, full name and SID.