Get AdministratorsMembers SIDs in .NET CORE 2

≡放荡痞女 提交于 2021-01-27 14:00:51

问题


I wrote this function to retrieve all Administrators Members SIDs:

private IList<byte[]> GetAdministratorsMembersSIDs()
{
    IList<byte[]> adminMembers = new List<byte[]>();

    SecurityIdentifier id = new SecurityIdentifier(administratorsSid);
    string name = id.Translate(typeof(NTAccount)).Value.Split('\\')[1];

    using (DirectoryEntry adminGroupEntry = new DirectoryEntry(string.Format("WinNT://./{0},group", name)))
    {                
        foreach (object member in (IEnumerable)adminGroupEntry.Invoke("Members"))
        {
            using (DirectoryEntry memberEntry = new DirectoryEntry(member))
            {
                adminMembers.Add((byte[])memberEntry.InvokeGet("objectSid"));
            }
        }
    }

    return adminMembers;
}

In .NET Core 2.1 adminGroupEntry.Invoke("Members") throw a System.PlatformNotSupportedException: IDispatch and IDispatchEx are not supported.
Anyone knows a workaround compatible in .NET Core 2.1 ?

[EDIT]
Issue fixed in .NET Core 3.0

来源:https://stackoverflow.com/questions/50601929/get-administratorsmembers-sids-in-net-core-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!