enumerate local/domain members from local group



I need to get the members of a local group that contains local as well as
domain groups in it. The following code only returns the local members from a
group.
Anyone can suggest ideas?. I am running the code from a web page in asp.net
2.0, the reason why I use userID/Password to connect to remote server.

public string[] GetLocalGroupMembers(string strComputer, string strUser,
string strPswd)
{
DirectoryEntry oComputer;
try
{
oComputer = new DirectoryEntry("WinNT://" + strComputer,
strUser, strPswd);
}
catch (Exception)
{
return null;
}

string strOut = "";

DirectoryEntries ds = oComputer.Children;
foreach (DirectoryEntry group in ds)
{
if (group.SchemaClassName.Equals("Group"))
{
if (strOut != "")
strOut += ";";
strOut += group.Properties["Name"].Value;

DirectoryEntry oGroup;
try
{
// get the group object
oGroup = new DirectoryEntry("WinNT://" + strComputer +
"/" + group.Properties["Name"].Value, strUser, strPswd,
AuthenticationTypes.Secure);
}
catch (Exception)
{
return null;
}

foreach (object obj in (IEnumerable)oGroup.Invoke("members"))
{
// save the member name
using (DirectoryEntry user = new DirectoryEntry(obj))
{
strOut += ";\t" + user.Name;
}
}
}
}

string[] arrGroups = null;

if (strOut != "")
{
arrGroups = strOut.Split(';');
}
return (arrGroups);
}



--
soler
.



Relevant Pages

  • Problem beim automatisierten erstellen einer Website
    ... Public Shared Function CreateWebSite(ByVal webSiteName As String, ... ' Find unused ID value for new web site ... Dim e As DirectoryEntry ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Problem beim automatisiertn erstellen einer Website
    ... Public Shared Function CreateWebSite(ByVal webSiteName As String, ... ' Find unused ID value for new web site ... Dim e As DirectoryEntry ...
    (microsoft.public.de.inetserver.iis)
  • Re: ADFS Development Issues
    ... Public Function IsUserAuthenticated(ByVal strAdPath As String, ... On Apr 22, 5:23 am, "Joe Kaplan" ... You can use that to build a directoryentry to use as the search root. ... user's credentials. ...
    (microsoft.public.windows.server.active_directory)
  • Re: A question in the objects size.
    ... > int id; ... > String name; ... then the order in which the base and derived members occur could ... leeway in deciding how to arrange the member variables. ...
    (comp.lang.java.programmer)
  • DirectoryServices Add/Remove Manager to Direct Report
    ... public void AddDirectReport(string ManagerAlias, string UserAlias) ... DirectoryEntry deDirectReport = GetUser; ... this.SetProperty(deDirectReport, "manager", this.GetProperty(deManager, ... code is running fine with this account on my staging environment. ...
    (microsoft.public.dotnet.languages.csharp)