I'm new with ADSI with .Net. I'm developing a windows application to
get the NT group name based on the user id. The application installed
successfully on the target computer (OS NT with the latest patch and
DSclient). Here is the code:
int idx = System.Security.Principal.WindowsIdentity.GetCurre nt().Name.ToString().IndexOf("\\");
string gusernm = System.Security.Principal.WindowsIdentity.GetCurre nt().Name.Substring(idx
+ 1);
// WinNT provider - domain name
string domainPath = "WinNT://MYDOMAIN/";
DirectoryEntry groupEntry = new DirectoryEntry( domainPath + gusernm
,gusernm, "", authenticationTypes.Secure);
System.DirectoryServices.PropertyCollection pcoll =
groupEntry.Properties;
// Invoke Groups method.
object obGroups = groupEntry.Invoke("Groups");
// Create object for each group.
DirectoryEntry obGpEntry;
try
{
foreach (object ob in (IEnumerable)obGroups)
{
obGpEntry = new DirectoryEntry(ob);
MessageBox.Show(obGpEntry.Name, "Info", MessageBoxButtons.OK);
}
}
catch (Exception ex)
{
MessageBox.Show("error " + ex.ToString(), "Warning",
MessageBoxButtons.OK);
}
If I run the application on Windows 2K, it runs without any error.
But on NT40,
I gives an error. Can someone help me to solve this problem? Any
sample of code is helpful. Thanks much!!