A
andres
Can anyone suggest how to get the local and domain members from a local
group. The C# code is running from an ASP.NET 2.0 webpage.
The following code only returns the local members and not the domain
members as well.
//Start of Code
public string[] GetLocalGroups(string strComputer, string strUser,
string strPswd)
{
DirectoryEntry oComputer;
try
{
if (strUser == "" && strPswd == "")
oComputer = new DirectoryEntry("WinNT://" + strComputer);
else
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 += child.Properties["Name"].Value + "\t" +
child.Properties["Description"].Value;
strOut += group.Properties["Name"].Value;
DirectoryEntry oGroup;
try
{
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"))
{
using (DirectoryEntry user = new DirectoryEntry(obj))
{
strOut += ";\t" + user.Name;
}
}
}
}
string[] arrGroups = null;
if (strOut != "")
{
arrGroups = strOut.Split(';');
}
return (arrGroups);
}
// End Of Code
Thanks
Andres
group. The C# code is running from an ASP.NET 2.0 webpage.
The following code only returns the local members and not the domain
members as well.
//Start of Code
public string[] GetLocalGroups(string strComputer, string strUser,
string strPswd)
{
DirectoryEntry oComputer;
try
{
if (strUser == "" && strPswd == "")
oComputer = new DirectoryEntry("WinNT://" + strComputer);
else
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 += child.Properties["Name"].Value + "\t" +
child.Properties["Description"].Value;
strOut += group.Properties["Name"].Value;
DirectoryEntry oGroup;
try
{
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"))
{
using (DirectoryEntry user = new DirectoryEntry(obj))
{
strOut += ";\t" + user.Name;
}
}
}
}
string[] arrGroups = null;
if (strOut != "")
{
arrGroups = strOut.Split(';');
}
return (arrGroups);
}
// End Of Code
Thanks
Andres