我想回去获取使用VB.Net的网络域上的用户列表。
我将有域名可供我使用。
提前谢谢。
发布于 2011-08-12 20:52:45
它可能会在select查询中抛出错误。
请检查以下内容:
您是否在项目中添加了对System.Management程序集的引用?如果没有,请执行以下操作:
在VS中,单击Project菜单> add reference。
在.Net选项卡上,向下滚动直到看到System.Management。单击以进行选择,然后单击确定。
现在回到您的代码中,在类的最顶端,输入"Imports System.Management",您应该已经设置好了。
来源:
http://www.vbforums.com/showthread.php?t=560422
它对我来说没有任何问题。我能够获得域的所有用户名。
发布于 2009-11-26 02:48:01
使用System.DirectoryServices和System.DirectoryServices.ActiveDirectory,类似这样的代码可能会为您指明正确的方向:
Private Function GetDomainUsers(ByVal domainDirectoryEntry As DirectoryEntry, ByRef userList As IList) As Integer
Try
userList = New ArrayList()
Using domainDirectoryEntry
Dim ds As New DirectorySearcher(domainDirectoryEntry, "(&(objectCategory=person)(objectClass=user))", New String() {"distinguishedName"})
Using src As SearchResultCollection = ds.FindAll()
For Each sr As SearchResult In src
userList.Add(sr.Properties("distinguishedName")(0))
Next
End Using
End Using
Return userList.Count
Catch generatedExceptionName As Exception
userList = Nothing
Return -1
Finally
domainDirectoryEntry = Nothing
End TryEnd函数
发布于 2009-11-26 08:00:49
Imports System.Management
Imports System.Management.Instrumentation
Sub PrintDomainUsers()
Dim domainName As String = System.Environment.UserDomainName.ToString
Dim userQuery As SelectQuery = New SelectQuery("Win32_UserAccount", "Domain='" & domainName & "'")
Try
Dim userSearch As ManagementObjectSearcher = New ManagementObjectSearcher(userQuery)
For Each domainUser In userSearch.Get
Console.WriteLine(domainUser("Name"))
Next
Catch ex As Exception
Throw ex
End Try
End Sub这是可行的,但我如何按某个组进行过滤。我得到了成千上万的结果
https://stackoverflow.com/questions/1799068
复制相似问题