Tag: active directory

获取AD OU列表

我希望能够从Active Directory中提取当前OU的列表我已经在线查看一些示例代码,但是O似乎无法使其工作。 string defaultNamingContext; DirectoryEntry rootDSE = new DirectoryEntry(“LDAP://RootDSE”); defaultNamingContext = rootDSE.Properties[“defaultNamingContext”].Value.ToString(); DirectorySearcher ouSearch = new DirectorySearcher(rootDSE, “(objectClass=organizationalUnit)”, null, SearchScope.Subtree); MessageBox.Show(rootDSE.ToString()); try { SearchResultCollection collectedResult = ouSearch.FindAll(); foreach (SearchResult temp in collectedResult) { comboBox1.Items.Add(temp.Properties[“name”][0]); DirectoryEntry ou = temp.GetDirectoryEntry(); } 我得到的错误是提供商不支持搜索,无法搜索LDAP:// RootDSE任何想法? 对于每个返回的搜索结果,我想将它们添加到combobox中。 (不应该太难)

检查当前用户是否是活动目录组的成员

我需要检查当前用户是否是活动目录组的成员。 我开始将当前用户设置如下。 现在我想知道如何检查这个CurrentUser是在活动目录组“CustomGroup”中 string CurrentUser = WindowsIdentity.GetCurrent().Name;

从UserPrincipal对象获取nETBIOSName

我正在使用.Net库的System.DirectoryServices.AccountManagement部分连接到ActiveDirectory。 在GroupPrincipal对象上调用GetMembers()并过滤结果后,我现在拥有了UserPrincipal对象的集合 GroupPrincipal myGroup; // population of this object omitted here foreach (UserPrincipal user in myGroup.GetMembers(false).OfType()) { Console.WriteLine(user.SamAccountName); } 上面的代码示例将打印出“TestUser1”之类的用户名。 我需要将这些与来自“DOMAIN \ TestUser1”格式的另一个应用程序的列表进行比较。 如何从UserPrincipal对象获取“DOMAIN”部分? 我不能只是附加一个已知的域名,因为涉及多个域,我需要区分DOMAIN1 \ TestUser1和DOMAIN2 \ TestUser2。

PrincipalContext.ValidateCredentials始终返回FALSE

我有一个MVC应用程序需要登录并validation用户对Active Directory。 我正在使用PrincipalContext.ValidateCredentials方法,但总是获得false的身份validation。 连接到服务器很好。 问题似乎发生在ValidateCredentials 。 这是我的代码: public static bool IsAuthenticated(string domain, string username, string pwd) { bool IsAuthenticated = false; try { PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, domain, “DC=c1w,DC=com”); username = “c1w\\” + username; IsAuthenticated = insPrincipalContext.ValidateCredentials(username, pwd); } catch (Exception ex) { // Rethrow this exception ExceptionPolicy.HandleException(ex, “Exception Policy”); } return IsAuthenticated; } […]

如何伪造Active Directory?

我正在使用C#开发一个需要针对Active Directory进行身份validation的应用程序。 我有Windows 7,无法在本地安装Active Directory。 我无权访问具有Active Directory的现有服务器(通过连接到VPN的十个步骤除外)。 我宁愿不创建运行Windows Server的虚拟机。 有没有可能在内存中运行并拦截AD调用以返回伪造数据? 如果它不存在,从理论上讲,将它拉下来需要什么?

从ActiveDirectory检索用户帐户过期

我正在尝试从帐户中检索到期日期。 我试过了 DirectoryEntry user = new DirectoryEntry(iMem); var AccountExpiration = DateTime.FromFileTime((int)user.Properties[“accountExpires”].Value); 它不起作用,只给我错误“指定的演员表无效”。 我用的时候 var AccountExpiration = user.Properties[“accountExpires”]; 返回一个我无法读取的com对象。 使用windows powershell,工作正常,我不明白为什么这不会工作… 这是我在powershell中使用的代码 $Expires = [datetime]::FromFileTime($tmpUser.accountExpires)

如果OU包含3000个用户,如何使用DirectorySearcher查找所有用户?

我用这个代码: DirectoryEntry objEntry; DirectorySearcher objSearchEntry; SearchResultCollection objSearchResult; string strFilter = “(&(objectCategory=User))”; objEntry = new DirectoryEntry(conOUPath, conUser, conPwd, AuthenticationTypes.Secure); objEntry.RefreshCache(); objSearchEntry = new DirectorySearcher(objEntry); objSearchEntry.Filter=strFilter; objSearchEntry.SearchScope=SearchScope.Subtree; objSearchEntry.CacheResults=false; objSearchResult=objSearchEntry.FindAll(); 每次只返回1000个用户,但该OU中有3000个用户。 我怎样才能找到所有这些?

使用c#删除活动目录中的用户

我写了一些代码,但没有工作,它抛出exception“发生了一个操作错误。” 代码—> DirectoryEntry dirEntry = new DirectoryEntry(“LDAP path”, “admin-username”, “admin-password”); dirEntry.Properties[“member”].Remove(“username-delete”); dirEntry.CommitChanges(); dirEntry.Close(); 给我一些想法摆脱这些事情..

如何检测我的程序是否在Active Directory环境中运行?

如何检测我的程序是否在Active Directory环境中运行? 我正在使用C#和.Net 2.0

使用登录名在Active Directory中查找用户

我可能只是愚蠢,但我正在尝试使用登录名(“域\用户”)从C#中找到Active Directory中的用户。 我的“Skeleton”AD搜索function通常如下所示: de = new DirectoryEntry(string.Format(“LDAP://{0}”, ADSearchBase), null, null, AuthenticationTypes.Secure); ds = new DirectorySearcher(de); ds.SearchScope = SearchScope.Subtree; ds.PropertiesToLoad.Add(“directReports”); ds.PageSize = 10; ds.ServerPageTimeLimit = TimeSpan.FromSeconds(2); SearchResult sr = ds.FindOne(); 现在,如果我有用户的完整DN(ADSearchBase通常指向Active Directory中的“我们的用户”OU),那么这是有效的,但我根本不知道如何根据“domain \ user”语法查找用户。 任何指针?