简体   繁体   中英

How can I get the list of user accounts that Windows presents on the Log-On screen?

I'm using NetQueryDisplayInformation (I've already tried the NetUserEnum function) to get the set of user accounts on the local machine. I can get all the accounts this way - but I only want the accounts associated with actual human beings, and not, for example, hidden accounts used for software updates.

After reading the MSDN documentation on the relevant structures and similar Stack questions , I see nothing that can allow me to filter to just the accounts that I need.

Ideally, someone will have a simple and reliable solution that:

  1. Doesn't involve using undocumented registry entries
  2. Doesn't rely on enumerating user folders on disk
  3. I'm not going to try to build an exhaustive list of non-real-user accounts
  4. For technical reasons, WMI is not an option

Any ideas?

[Much later] Got the answer, but not here - just enumerate the groups for each user. "Real human" accounts will be a member of one or more of Administrator, Power User, User, Guest.

You may be able to use the NetUserEnum function. It should return a list of all the user accounts on the system. I've not had to use this function personally so I can't provide any spectacular code examples, but the MSDN information sounds like what you are looking for.

You can use NetQueryDisplayInformation API, combine with bitwise check on user info flag.

I have exactly the same requirements, so I cook sample code (modified from MSDN GROUP query).

The user flags I used are:

UF_NORMAL_ACCOUNT
UF_ACCOUNTDISABLE
UF_PASSWD_NOTREQD ---> this ensure we get Human account, Human account always requires password.

working code at: http://www.cceye.com/list-system-normal-user-account-only/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM