Active Directory字符串不返回任何结果 [英] Active Directory String returns no results

查看:56
本文介绍了Active Directory字符串不返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Active Directory中搜索计算机名称,并在用户从组合框中选择计算机所在的正确房间号后在列表框中显示结果.我已将dirSearcher.Filter设置为仅在列表框中显示计算机,并在下面显示以下代码,并且所有计算机名称都能正确显示.

I am trying to search for computer names in my Active directory and display the results in a list box once the user selects the correct room number the computers are in from a combo box. I have setup my dirSearcher.Filter to only display computers in my list box with the following code below and all the computers names display correctly.

<br />
dirSearcher.Filter = ("(objectClass=Computer)")<br />


但是,当我将另一部分添加到过滤器中时,该过滤器允许用户从组合框中选择房间号,并且在计算机名中包含房间号的所有计算机都显示为我的搜索,如果没有返回结果,我将尽可能地寻求帮助有人指出正确的方向是正确的方法来按计算机名称过滤并在列表框中显示结果.我拥有的代码在任何帮助下都值得赞赏.


But when I add the other part to my filter which allows the user to select the room number from a combo box and all the computers that contain the room# in the computer name to display my search returns no results I would like help if possible for someone to point me in the right direction as the correct way to filter by computer name and display the results in the listbox. The code I have is below any help is appreciated.

<br />
<pre lang="vb"><br />
       Dim compuDesc As String<br />
       compuDesc = ComboBox1.Text<br />
       Dim dirEntry As DirectoryEntry = GetDirectoryEntry()<br />
       Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)<br />
       dirSearcher.Filter = "(&(objectClass=Computer)(name = RM131A*))"<br />
       dirSearcher.PropertiesToLoad.Add("name")<br />
       Dim dirSearchResults As SearchResult<br />
       For Each dirSearchResults In dirSearcher.FindAll()<br />
           ListView1.Items.Add(dirSearchResults.GetDirectoryEntry().Name.ToString())<br />
       Next</pre><br />
<br />

推荐答案

如果看不到您编写的其余Active Directory代码,我建议本文也许可以为您提供帮助

Active Directory [
Without seeing the rest of the Active Directory code that you have written I would suggest this article maybe able to help you

Active Directory [^]


先生,您可以像下面这样使用String.Fomat:

sir, you can use String.Fomat just like:

dirSearcher.Filter = String.Fomat("(objectClass='Computer') and (cn ='{0}')", compuDesc )


我不是VB专家,但它是否具有类似于string.Contains的内容?
I am no VB guru, but does it have anything like string.Contains?


这篇关于Active Directory字符串不返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆