मैं यह निर्धारित करने की कोशिश कर रहा हूं कि एडी में कोई उपयोगकर्ता खाता सक्षम है या नहीं।क्यों UserPrincipal.Enabled अलग-अलग मान देता है?
string domain = "my domain";
string group = "my security group";
string ou = "my OU";
//init context
using (var cnt= new PrincipalContext(ContextType.Domain, domain))
{
//find the necessary security group
using (GroupPrincipal mainGroup
= GroupPrincipal.FindByIdentity(cnt, IdentityType.Guid, group))
{
if (mainGroup != null)
{
//get the group's members
foreach (var user in mainGroup.GetMembers()
.OfType<UserPrincipal>()
.Where(u => u.DistinguishedName.Contains(ou)))
{
//ensure that all the info about the account is loaded
//by using FindByIdentity as opposed to GetMembers
var tmpUser= UserPrincipal.FindByIdentity(cnt,
user.SamAccountName);
//actually I could use `user` variable,
//as it gave the same result as `tmpUser`.
//print the account info
Console.WriteLine(tmpUser.Name + "\t" +
tmpUser.Enabled.HasValue + "\t" +
tmpUser.Enabled.Value);
}
}
}
}
समस्या है, जब मैं एक प्रशासनिक खाते के अंतर्गत इस कोड चलाने के लिए, मैं वास्तविक परिणाम प्राप्त है, जबकि जब मैं यह एक गैर priviledged खाते के अंतर्गत चलाने के लिए, user.Enabled
रिटर्न false
: इसके लिए मैं निम्नलिखित कोड का उपयोग कुछ खातों के लिए, जबकि यह true
होना चाहिए।
केवल समान क्ष & मैं खोज करने में कामयाब एक
- UserPrincipal.Enabled returns False for accounts that are in fact enabled?
- Everything in Active Directory via C#.NET 3.5 (Using System.DirectoryServices.AccountManagement)
जो यहाँ मदद नहीं कर रहे हैं।
ऐसा क्यों है? इस जानकारी को गैर-निजीकृत खाते के तहत प्राप्त करने के मेरे विकल्प क्या हैं?
यहाँ एक और तरीका है: How to determine if user account is enabled or disabled:
private bool IsActive(DirectoryEntry de)
{
if (de.NativeGuid == null)
return false;
int flags = (int)de.Properties["userAccountControl"].Value;
if (!Convert.ToBoolean(flags & 0x0002))
return true;
else
return false;
}
एक ही दृष्टिकोण Active Directory Objects and C# में वर्णित है।
हालांकि एक अप्रतिबंधित उपयोगकर्ता खाते के तहत चलते समय, userAccountControl
विशेषता null
है और खाते की स्थिति निर्धारित करना संभव नहीं है।
वैकल्पिक हल यहाँ PrincipalContext Constructor उपयोग करने के लिए, ई का उपयोग करने के लिए पर्याप्त विशेषाधिकार के साथ एक उपयोगकर्ता की साख को निर्दिष्ट है।
यह मेरे लिए अस्पष्ट रहता है, क्यों गैर-वंचित उपयोगकर्ता को एडी तक पहुंच थी, और कुछ निश्चित खाता विशेषताओं के मूल्य नहीं मिल सके। शायद इसका सी # के साथ कुछ लेना देना नहीं है, और इसे एडी में कॉन्फ़िगर किया जाना चाहिए ...
यदि आप अपने लिंक से सटीक निर्देश जोड़ सकते हैं, तो आपका उत्तर टूटा लिंक होने से बेहतर और सुरक्षित होगा! – ForceMagic
धन्यवाद। लिंक से प्रासंगिक जानकारी के ब्लॉकक्वाट जोड़ा गया। –