c# - Query only returns groups that have users -
the code below returns list of groups , associated members on machine. why return populated groups. example create new user group on machine , not returned on query. if add user user group return in query. there fix query?
c# code
var sgroupname = ""; var susername = ""; managementobjectsearcher searchresult = new managementobjectsearcher("root\\cimv2", "select * win32_groupuser"); foreach (managementobject queryobj in searchresult.get()) { sgroupname = queryobj["groupcomponent"].tostring().split(new[] { "name=" }, stringsplitoptions.none).last().trim('"'); susername = queryobj["partcomponent"].tostring().split(new[] { "name=" }, stringsplitoptions.none).last().trim('"'); }
try this:
var searchresult = new managementobjectsearcher("root\\cimv2", "select * win32_group");
Comments
Post a Comment