Is there a way to get in C# a list of local groups and users, when the windows machine is no AD member and an LDAP search can't be used?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You can use P/Invoke to call the native network management API to get local user and group names:
The API allows you to get various information about users. If you only want names you can use this function:
The LINQ statement is used to "parse" the buffer that contains
USER_INFO_0
strutures. If you are querying for additional information you will have to do more elaborate "parsing".Likewise you can get local group names:
The structures in the buffer are
LOCALGROUP_INFO_0
with the same layout as theUSER_INFO_0
structure so the "parsing" code is identical.Finally, here is how to get group membership using the
LOCALGROUP_MEMBERS_INFO_3
structure: