本文整理汇总了C#中System.DirectoryServices.DirectoryEntry.InvokeGet方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry.InvokeGet方法的具体用法?C# DirectoryEntry.InvokeGet怎么用?C# DirectoryEntry.InvokeGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DirectoryServices.DirectoryEntry
的用法示例。
在下文中一共展示了DirectoryEntry.InvokeGet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStatus
private string GetStatus(string appPoolName)
{
string status = string.Empty;
string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
int intStatus = 0;
try
{
DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
intStatus = (int)w3svc.InvokeGet("AppPoolState");
switch (intStatus)
{
case 2:
status = "Running";
break;
case 4:
status = "Stopped";
break;
default:
status = "Unknown";
break;
}
}
catch
{
return null;
}
return status;
}
示例2: GetObjectGuid
public static Guid GetObjectGuid(DirectoryEntry d)
{
object gid = null;
try
{
gid = d.InvokeGet("objectGuid");
}
catch (Exception ex)
{
throw new Exception(string.Format("Could not get GUID on entry: {0}", d.Path), ex);
}
byte[] b = gid as byte[];
Guid g = new Guid(b);
return g;
}
示例3: GetObjectCategory
public static string GetObjectCategory(DirectoryEntry d)
{
object c = d.InvokeGet("objectCategory");
return c.ToString();
}
示例4: GrantFullAccessToFolder
public static void GrantFullAccessToFolder(string folderPath, DirectoryEntry de, string userName, string principalDomain)
{
try
{
if (!System.IO.Directory.Exists(folderPath))
System.IO.Directory.CreateDirectory(folderPath);
DirectoryInfo dInfo = new DirectoryInfo(folderPath);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
byte[] sidByte = de.InvokeGet("objectSid") as byte[];
SecurityIdentifier sid = new SecurityIdentifier(sidByte, 0);
string id = userName + "@" + principalDomain;
dSecurity.AddAccessRule(new FileSystemAccessRule(sid, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);
}
catch (Exception ex)
{
throw new Exception(string.Format("Error granting user {0} full persmissions to folder {1}", userName, folderPath), ex);
}
}
示例5: ContainerIsSuperiorOfUser
//
// This function goes through each of the object class values for the container to determine
// whether the object class is one of the possible superiors of the user object
//
private bool ContainerIsSuperiorOfUser(DirectoryAttribute objectClass)
{
ArrayList possibleSuperiorsList = new ArrayList();
//
// first get a list of all the classes from which the user class is derived
//
DirectoryEntry de = new DirectoryEntry(GetADsPath("schema") + "/user", GetUsername(), GetPassword(), AuthenticationTypes);
ArrayList classesList = new ArrayList();
bool derivedFromlistEmpty = false;
object value = null;
try
{
value = de.InvokeGet("DerivedFrom");
}
catch (COMException e)
{
if (e.ErrorCode == unchecked((int) 0x8000500D))
{
derivedFromlistEmpty = true;
}
else
throw;
}
if (!derivedFromlistEmpty)
{
if (value is ICollection)
{
classesList.AddRange((ICollection) value);
}
else
{
// single value
classesList.Add((string) value);
}
}
//
// we will use this list to create a filter of all the classSchema objects that we need to determine the recursive list
// of "possibleSecuperiors". We need to add the user class also.
//
classesList.Add("user");
//
// Now search under the schema naming context for all these classes and get the "possSuperiors" and "systemPossSuperiors" attributes
//
DirectoryEntry schemaNC = new DirectoryEntry(GetADsPath((string) rootdse.Properties["schemaNamingContext"].Value), GetUsername(), GetPassword(), AuthenticationTypes);
DirectorySearcher searcher = new DirectorySearcher(schemaNC);
searcher.Filter = "(&(objectClass=classSchema)(|";
foreach(string supClass in classesList)
searcher.Filter += "(ldapDisplayName=" + supClass + ")";
searcher.Filter += "))";
searcher.SearchScope = System.DirectoryServices.SearchScope.OneLevel;
searcher.PropertiesToLoad.Add("possSuperiors");
searcher.PropertiesToLoad.Add("systemPossSuperiors");
SearchResultCollection resCol = searcher.FindAll();
try
{
foreach (SearchResult res in resCol)
{
possibleSuperiorsList.AddRange(res.Properties["possSuperiors"]);
possibleSuperiorsList.AddRange(res.Properties["systemPossSuperiors"]);
}
}
finally
{
resCol.Dispose();
}
//
// Now we have the list of all the possible superiors, check if the objectClass that was specified as a parameter
// to this function is one of these values, if so, return true else false
//
foreach (string objectClassValue in objectClass.GetValues(typeof(string)))
{
if (possibleSuperiorsList.Contains(objectClassValue))
return true;
}
return false;
}
示例6: GetUserObjectAttributes
private Hashtable GetUserObjectAttributes()
{
DirectoryEntry de = new DirectoryEntry(directoryInfo.GetADsPath("schema") + "/user", directoryInfo.GetUsername(), directoryInfo.GetPassword(), directoryInfo.AuthenticationTypes);
object value = null;
bool listEmpty = false;
Hashtable attributes = new Hashtable(StringComparer.OrdinalIgnoreCase);
try
{
value = de.InvokeGet("MandatoryProperties");
}
catch (COMException e)
{
if (e.ErrorCode == unchecked((int) 0x8000500D))
{
listEmpty = true;
}
else
throw;
}
if (!listEmpty)
{
if (value is ICollection)
{
foreach (string attribute in (ICollection) value)
{
if (!attributes.Contains(attribute))
attributes.Add(attribute, null);
}
}
else
{
// single value
if (!attributes.Contains(value))
attributes.Add(value, null);
}
}
listEmpty = false;
try
{
value = de.InvokeGet("OptionalProperties");
}
catch (COMException e)
{
if (e.ErrorCode == unchecked((int) 0x8000500D))
{
listEmpty = true;
}
else
throw;
}
if (!listEmpty)
{
if (value is ICollection)
{
foreach (string attribute in (ICollection) value)
{
if (!attributes.Contains(attribute))
attributes.Add(attribute, null);
}
}
else
{
// single value
if (!attributes.Contains(value))
attributes.Add(value, null);
}
}
return attributes;
}
示例7: GetRangeUpperForSchemaAttribute
private int GetRangeUpperForSchemaAttribute(string attributeName)
{
int rangeUpper = -1;
DirectoryEntry propertyEntry = new DirectoryEntry(directoryInfo.GetADsPath("schema") + "/" + attributeName, directoryInfo.GetUsername(), directoryInfo.GetPassword(), directoryInfo.AuthenticationTypes);
try
{
rangeUpper = (int) propertyEntry.InvokeGet("MaxRange");
}
catch (TargetInvocationException e)
{
//
// if the inner exception is a comexception with error code 0x8007500d, then the max range is not set
// so we ignore that exception
//
if (!((e.InnerException is COMException) && (((COMException)e.InnerException).ErrorCode == unchecked((int) 0x8000500d))))
throw;
}
return rangeUpper;
}
示例8: GetValidatedSchemaMapping
private string GetValidatedSchemaMapping(string valueName, string attributeName, out int maxLength)
{
if (String.Compare(valueName, "attributeMapUsername", StringComparison.Ordinal) == 0)
{
if (directoryInfo.DirectoryType == DirectoryType.AD)
{
//
// username can only be mapped to "sAMAccountName", "userPrincipalName"
//
if ((!StringUtil.EqualsIgnoreCase(attributeName, "sAMAccountName"))
&& (!StringUtil.EqualsIgnoreCase(attributeName, "userPrincipalName")))
throw new ProviderException(SR.GetString(SR.ADMembership_Username_mapping_invalid));
}
else
{
//
// for ADAM, username can only be mapped to "userPrincipalName"
//
if (!StringUtil.EqualsIgnoreCase(attributeName, "userPrincipalName"))
throw new ProviderException(SR.GetString(SR.ADMembership_Username_mapping_invalid_ADAM));
}
}
else
{
//
// ensure that we are not already using this attribute
//
if (attributesInUse.Contains(attributeName))
throw new ProviderException(SR.GetString(SR.ADMembership_mapping_not_unique, valueName, attributeName));
//
// ensure that the attribute exists on the user object
//
if (!userObjectAttributes.Contains(attributeName))
throw new ProviderException(SR.GetString(SR.ADMembership_MappedAttribute_does_not_exist_on_user, attributeName, valueName));
}
try
{
//
// verify that this is an existing property and it's syntax is correct
//
DirectoryEntry propertyEntry = new DirectoryEntry(directoryInfo.GetADsPath("schema") + "/" + attributeName, directoryInfo.GetUsername(), directoryInfo.GetPassword(), directoryInfo.AuthenticationTypes);
//
// to get the syntax we need to invoke the "syntax" property
//
string syntax = (string) propertyEntry.InvokeGet("Syntax");
//
// check that the syntax is as per the syntaxes table
//
if (!StringUtil.EqualsIgnoreCase(syntax, (string) syntaxes[valueName]))
throw new ProviderException(SR.GetString(SR.ADMembership_Wrong_syntax, valueName, (string) syntaxes[valueName]));
//
// if the type is "DirectoryString", then set the maxLength value if any
//
maxLength = -1;
if (StringUtil.EqualsIgnoreCase(syntax, "DirectoryString"))
{
try
{
maxLength = (int) propertyEntry.InvokeGet("MaxRange");
}
catch (TargetInvocationException e)
{
//
// if the inner exception is a comexception with error code 0x8007500d, then the max range is not set
// so we ignore that exception
//
if (!((e.InnerException is COMException) && (((COMException)e.InnerException).ErrorCode == unchecked((int) 0x8000500d))))
throw;
}
}
//
// unless this is the username (which we already know is mapped
// to a single valued attribute), the attribute should be single valued
//
if (String.Compare(valueName, "attributeMapUsername", StringComparison.Ordinal) != 0)
{
bool isMultiValued = (bool) propertyEntry.InvokeGet("MultiValued");
if (isMultiValued)
throw new ProviderException(SR.GetString(SR.ADMembership_attribute_not_single_valued, valueName));
}
}
catch (COMException e)
{
if (e.ErrorCode == unchecked((int) 0x80005000))
throw new ProviderException(SR.GetString(SR.ADMembership_MappedAttribute_does_not_exist, attributeName, valueName), e);
else
throw;
}
//
//.........这里部分代码省略.........
示例9: IsAccountLockOut
/// <summary>
/// 查询制定用户是否是锁定状态
/// </summary>
/// <param name="de"></param>
/// <returns></returns>
public static bool IsAccountLockOut(DirectoryEntry de )
{
return Convert.ToBoolean(de.InvokeGet("IsAccountlocked"));
}
示例10: buildWarningSegment
private void buildWarningSegment(DirectoryEntry result)
{
//Creates warning headers for differnt kinds of user errors
StringBuilder sb = new StringBuilder();
var flags = (int)result.Properties["userAccountControl"].Value;
//Account is disabled!
const int ufAccountDisable = 0x0002;
if (((flags & ufAccountDisable) == ufAccountDisable))
{
errorUserDisabled.Style.Clear();
}
//Accont is locked
if ((Convert.ToBoolean(result.InvokeGet("IsAccountLocked"))))
{
errorUserLockedDiv.Style.Clear();
}
//Password Expired
string attName = "msDS-User-Account-Control-Computed";
result.RefreshCache(attName.Split(','));
const int UF_LOCKOUT = 0x0010;
int userFlags = (int)result.Properties["msDS-User-Account-Control-Computed"].Value;
if ((userFlags & UF_LOCKOUT) == UF_LOCKOUT)
{
errorPasswordExpired.Style.Clear();
}
//Missing Attributes
if (!(result.Properties.Contains("aauUserClassification") && result.Properties.Contains("aauUserStatus") && (result.Properties.Contains("aauStaffID") || result.Properties.Contains("aauStudentID"))))
{
errorMissingAAUAttr.Style.Clear();
}
if (!userIsInRightOU(result))
{
//Show warning
warningNotStandardOU.Style.Clear();
}
else
{
divFixuserOU.Visible = false;
}
//Password is expired and warning before expire (same timeline as windows displays warning)
}
示例11: GrantfullAccessToFolder
public void GrantfullAccessToFolder(string folderPath, DirectoryEntry de)
{
try
{
DirectoryInfo dInfo = new DirectoryInfo(folderPath);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
byte[] sidByte = de.InvokeGet("objectSid") as byte[];
SecurityIdentifier sid = new SecurityIdentifier(sidByte, 0);
string id = DefaultApp.LDAPDomain + "\\" + UserName;
dSecurity.AddAccessRule(new FileSystemAccessRule(sid, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);
}
catch (Exception ex)
{
throw new Exception(string.Format("Error granting user {0} full persmissions to folder {1}", UserName, folderPath), ex);
}
}
示例12: ValidateCredentials
public static string ValidateCredentials(string userName, string password, bool requiresLdap, bool requiresAdmin)
{
LoggingUtils.WriteInfo("Validating Windows Credentials", "UserName", userName, "RequiresLDAP", requiresLdap.ToString(), "RequiresAdmin", requiresAdmin.ToString());
userName = FormatAsLocalUserName(userName);
if (userName.Contains(@"\"))
{
// Validate credentials as domain acccount
string[] userParts = userName.Split(@"\".ToCharArray());
try
{
using (DirectoryEntry deDirEntry = new DirectoryEntry(
"LDAP://" + ConvertDomainNameToLdapPath(FriendlyDomainToLdapDomain(userParts[0])),
userParts[1], password, AuthenticationTypes.Secure))
{
deDirEntry.InvokeGet("cn");
}
// Check if user belongs to the Windows Administrators group if applicable
if (requiresAdmin)
{
if (!IsUserAdmin(userParts[1], password, userParts[0]))
{
return "Specified user must be an Administrator on the local machine.";
}
}
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
return string.Format(CultureInfo.InvariantCulture, "LDAP account verification failed.\n\n{0}", ex.InnerException.Message);
}
return string.Format(CultureInfo.InvariantCulture, "LDAP account verification failed.\n\n{0}", ex.Message);
}
}
else
{
// Check if LDAP was required
if (requiresLdap)
{
return "Account verification failed.\n\nAccount must be a network domain account.";
}
// Validate credentials as local account
try
{
using (DirectoryEntry deDirEntry = new DirectoryEntry(
"WinNT://" + Environment.MachineName + ",computer",
Environment.MachineName + @"\" + userName, password, AuthenticationTypes.Secure))
{
deDirEntry.InvokeGet("OperatingSystem");
}
// Check if user belongs to the Windows Administrators group if applicable
if (requiresAdmin)
{
if (!IsUserAdmin(userName, password, Environment.MachineName))
{
return "Specified user must be an Administrator on the local machine.";
}
}
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
return string.Format(CultureInfo.InvariantCulture, "Account verification failed.\n\n{0}", ex.InnerException.Message);
}
return string.Format(CultureInfo.InvariantCulture, "Account verification failed.\n\n{0}", ex.Message);
}
}
return null;
}
示例13: GetStatus
private static string GetStatus(string appPoolName)
{
string status = string.Empty;
string appPoolPath = Constants.AddressHeader + Constants.AppPools + "/" + appPoolName;
int intStatus = 0;
try
{
var w3svc = new DirectoryEntry(appPoolPath);
intStatus = (int)w3svc.InvokeGet(Constants.AppPoolState);
return ((PoolStates)intStatus).ToString();
}
catch
{
return PoolStates.Unknown.ToString();
}
}
示例14: GetValidatedSchemaMapping
private string GetValidatedSchemaMapping(string valueName, string attributeName, out int maxLength)
{
if (string.Compare(valueName, "attributeMapUsername", StringComparison.Ordinal) == 0)
{
if (this.directoryInfo.DirectoryType != DirectoryType.AD)
{
if (!System.Web.Util.StringUtil.EqualsIgnoreCase(attributeName, "userPrincipalName"))
{
throw new ProviderException(System.Web.SR.GetString("ADMembership_Username_mapping_invalid_ADAM"));
}
}
else if (!System.Web.Util.StringUtil.EqualsIgnoreCase(attributeName, "sAMAccountName") && !System.Web.Util.StringUtil.EqualsIgnoreCase(attributeName, "userPrincipalName"))
{
throw new ProviderException(System.Web.SR.GetString("ADMembership_Username_mapping_invalid"));
}
}
else
{
if (this.attributesInUse.Contains(attributeName))
{
throw new ProviderException(System.Web.SR.GetString("ADMembership_mapping_not_unique", new object[] { valueName, attributeName }));
}
if (!this.userObjectAttributes.Contains(attributeName))
{
throw new ProviderException(System.Web.SR.GetString("ADMembership_MappedAttribute_does_not_exist_on_user", new object[] { attributeName, valueName }));
}
}
try
{
DirectoryEntry entry = new DirectoryEntry(this.directoryInfo.GetADsPath("schema") + "/" + attributeName, this.directoryInfo.GetUsername(), this.directoryInfo.GetPassword(), this.directoryInfo.AuthenticationTypes);
string str = (string) entry.InvokeGet("Syntax");
if (!System.Web.Util.StringUtil.EqualsIgnoreCase(str, (string) this.syntaxes[valueName]))
{
throw new ProviderException(System.Web.SR.GetString("ADMembership_Wrong_syntax", new object[] { valueName, (string) this.syntaxes[valueName] }));
}
maxLength = -1;
if (System.Web.Util.StringUtil.EqualsIgnoreCase(str, "DirectoryString"))
{
try
{
maxLength = (int) entry.InvokeGet("MaxRange");
}
catch (TargetInvocationException exception)
{
if (!(exception.InnerException is COMException) || (((COMException) exception.InnerException).ErrorCode != -2147463155))
{
throw;
}
}
}
if ((string.Compare(valueName, "attributeMapUsername", StringComparison.Ordinal) != 0) && ((bool) entry.InvokeGet("MultiValued")))
{
throw new ProviderException(System.Web.SR.GetString("ADMembership_attribute_not_single_valued", new object[] { valueName }));
}
}
catch (COMException exception2)
{
if (exception2.ErrorCode == -2147463168)
{
throw new ProviderException(System.Web.SR.GetString("ADMembership_MappedAttribute_does_not_exist", new object[] { attributeName, valueName }), exception2);
}
throw;
}
return attributeName;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:65,代码来源:ActiveDirectoryMembershipProvider.cs
示例15: GetUserObjectAttributes
private Hashtable GetUserObjectAttributes()
{
DirectoryEntry entry = new DirectoryEntry(this.directoryInfo.GetADsPath("schema") + "/user", this.directoryInfo.GetUsername(), this.directoryInfo.GetPassword(), this.directoryInfo.AuthenticationTypes);
object key = null;
bool flag = false;
Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase);
try
{
key = entry.InvokeGet("MandatoryProperties");
}
catch (COMException exception)
{
if (exception.ErrorCode != -2147463155)
{
throw;
}
flag = true;
}
if (!flag)
{
if (key is ICollection)
{
foreach (string str in (ICollection) key)
{
if (!hashtable.Contains(str))
{
hashtable.Add(str, null);
}
}
}
else if (!hashtable.Contains(key))
{
hashtable.Add(key, null);
}
}
flag = false;
try
{
key = entry.InvokeGet("OptionalProperties");
}
catch (COMException exception2)
{
if (exception2.ErrorCode != -2147463155)
{
throw;
}
flag = true;
}
if (!flag)
{
if (key is ICollection)
{
foreach (string str2 in (ICollection) key)
{
if (!hashtable.Contains(str2))
{
hashtable.Add(str2, null);
}
}
return hashtable;
}
if (!hashtable.Contains(key))
{
hashtable.Add(key, null);
}
}
return hashtable;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:68,代码来源:ActiveDirectoryMembershipProvider.cs