W
Will .H
Guest
Hi there,
I have a development issue to find out AD user - Pre-Windows 2000 User Logon name. I use the following code to extract the user logon name (pre-windows2000) and the error comes up.
using (System.DirectoryServices.DirectorySearcher searcher = new System.DirectoryServices.DirectorySearcher())
{
searcher.SearchRoot = domain;
searcher.PropertiesToLoad.Add("sAMAccountName");
searcher.PropertiesToLoad.Add("userPrincipalName");
searcher.PropertiesToLoad.Add("objectSid");
searcher.Filter = "(userPrincipalName=" + userNameOrEmail + ")";
try
{
using (System.DirectoryServices.SearchResultCollection results = searcher.FindAll())
{
if (results == null || results.Count == 0)
{ } //continue;
else
{
byte[] SID = null;
if (results[0].Properties["objectSid"].Count > 0)
{
SID = (byte[])results[0].Properties["objectSid"][0];
//string sid = "S-1-5-21-789336058-507921405-854245398-9938";
string sid = GetSidString(SID);
//this line error -- >
string account = new System.Security.Principal.SecurityIdentifier(sid).Translate(typeof(System.Security.Principal.NTAccount)).ToString();
}
}
}
} // End Try
catch (System.Exception eX)
{ }
} // End Using searcher
the error happened at this line --- string account = new System.Security ........
the error is :
{"Some or all identity references could not be translated."}
Does anyone have any idea on it?? Thanks
Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.
Continue reading...
I have a development issue to find out AD user - Pre-Windows 2000 User Logon name. I use the following code to extract the user logon name (pre-windows2000) and the error comes up.
using (System.DirectoryServices.DirectorySearcher searcher = new System.DirectoryServices.DirectorySearcher())
{
searcher.SearchRoot = domain;
searcher.PropertiesToLoad.Add("sAMAccountName");
searcher.PropertiesToLoad.Add("userPrincipalName");
searcher.PropertiesToLoad.Add("objectSid");
searcher.Filter = "(userPrincipalName=" + userNameOrEmail + ")";
try
{
using (System.DirectoryServices.SearchResultCollection results = searcher.FindAll())
{
if (results == null || results.Count == 0)
{ } //continue;
else
{
byte[] SID = null;
if (results[0].Properties["objectSid"].Count > 0)
{
SID = (byte[])results[0].Properties["objectSid"][0];
//string sid = "S-1-5-21-789336058-507921405-854245398-9938";
string sid = GetSidString(SID);
//this line error -- >
string account = new System.Security.Principal.SecurityIdentifier(sid).Translate(typeof(System.Security.Principal.NTAccount)).ToString();
}
}
}
} // End Try
catch (System.Exception eX)
{ }
} // End Using searcher
the error happened at this line --- string account = new System.Security ........
the error is :
{"Some or all identity references could not be translated."}
Does anyone have any idea on it?? Thanks
Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.
Continue reading...