Tag: directoryentry

System.IO.FileNotFoundException:找不到网络路径。 在Windows 7上使用DirectoryEntry对象时出现exception

我正在尝试使用DirectoryEntry对象连接到远程Windows 7计算机。 这是我的代码 DirectoryEntry obDirEntry = new DirectoryEntry(“WinNT://hostName”, “hostName\\testUser”, “password123”, AuthenticationTypes.Secure); try { if (obDirEntry.Properties.Count > 0) { //ok } } catch (Exception excp) {} 如果我能够连接到远程Windows Server 2003机器或本地Windows 7机器,那么我没有得到任何错误。 但是,当我尝试连接到远程Windows 7机器时,我在线路上获得exceptionif (obDirEntry.Properties.Count > 0) Exception :System.IO.FileNotFoundException: The network path was not found. at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.GetInfo() at System.DirectoryServices.DirectoryEntry.RefreshCache() at System.DirectoryServices.DirectoryEntry.FillCache(String propertyName) at System.DirectoryServices.PropertyCollection.get_Count() 我能够ping远程窗口7 m / c。 […]

如何使用objectGUID获取DirectoryEntry?

我知道,我们可以像这样得到一个DirectoryEntry: string conPath = “LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com”; string conUser = “administrator”; string conPwd = “Iampassword”; DirectoryEntry de = new DirectoryEntry(conPath, conUser, conPwd, AuthenticationTypes.Secure); 我们可以像这样更改用户的密码: DirectorySearcher deSearch = new DirectorySearcher(); deSearch.SearchRoot = de; deSearch.Filter = String.Format(“sAMAccountName={0}”, “xumai”); SearchResultCollection results = deSearch.FindAll(); foreach (SearchResult objResult in results) { DirectoryEntry obj = objResult.GetDirectoryEntry(); obj.Invoke(“setPassword”, new object[] { “Welcome99” }); obj.CommitChanges(); […]

在C#中将本地用户添加到本地组

我可以很好地添加用户,但是我无法将其添加到本地组。 我收到这个错误: – 无法将成员添加到本地组或从本地组中删除该成员,因为该成员不存在。 这是我正在使用的代码。 我做错了什么? 它只是本地机器,我绝对有权这样做,而且该组织确实存在。 try { using (DirectoryEntry hostMachineDirectory = new DirectoryEntry(“WinNT://” + serverName)) { DirectoryEntries entries = hostMachineDirectory.Children; foreach (DirectoryEntry entry in entries) { if (entry.Name.Equals(userName, StringComparison.CurrentCultureIgnoreCase)) { // Update password entry.Invoke(“SetPassword”, password); entry.CommitChanges(); return true; } } DirectoryEntry obUser = entries.Add(userName, “User”); obUser.Properties[“FullName”].Add(“Used to allow users to login to Horizon. […]

如何使用PrincipalContext搜索全局编录(整个林)

myUserList AppUsers = new myUserList(); using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, domainName)) { UserPrincipal User = new UserPrincipal(pcxt); User.EmailAddress = emailString; PrincipalSearcher srch = new PrincipalSearcher(User); foreach (var principal in srch.FindAll()) { var p = (UserPrincipal)principal; myUserRow User = AppUsers.NewUsersRow(); User.FirstName = p.GivenName; User.LastName = p.Surname; User.Email = p.EmailAddress; AppUsers.AddUsersRow(User); } } 我有类似于上面的代码,使用PrincipalContext类在Active Directory中搜索用户信息。 正如您所看到的,我在搜索过程中传入了domainName。 […]

如何获取所有域名列表?

我正在尝试获取Windows登录对话框中可用的所有域(在域下拉列表中)。 我尝试了以下代码,但它只返回我登录的域。 我错过了什么吗? StringCollection domainList = new StringCollection(); try { DirectoryEntry en = new DirectoryEntry(); // Search for objectCategory type “Domain” DirectorySearcher srch = new DirectorySearcher(en, “objectCategory=Domain”); SearchResultCollection coll = srch.FindAll(); // Enumerate over each returned domain. foreach (SearchResult rs in coll) { ResultPropertyCollection resultPropColl = rs.Properties; foreach( object domainName in resultPropColl[“name”]) { domainList.Add(domainName.ToString()); } […]

如何知道我的DirectoryEntry是否真的连接到我的LDAP目录?

我正在连接到C#中的LDAP目录,所以我使用了DirectoryEntry类。 使用地址,登录名和密码执行“new DirectoryEntry”时,应该连接到LDAP目录。 但是,即使连接不起作用,它也会毫无问题地返回,并且设置了directoryentry变量。 所以我知道我的连接真的开了吗? 现在,我正在使用一个非常非常丑陋的黑客:我放了一个“if(mydirectory.SchemaEntry)”,如果没有建立连接会产生exception,因为DirectoryEntry的某些成员,例如SchemaEntry,不是如果连接失败,则设置。 但是1:在丑陋的等级2上需要11/10:在失败之前需要花费很多时间。 那么这样做的好方法是什么? 当然,微软必须提供一些东西(即使我使用的是LDAP目录而不是Active Directory)来了解我是否真的已经连接了?