VB 获取本地用户列表
VB Getting list of local users
我需要获取所有本地用户的方法。如果我只是去用户文件夹病得到本地用户和域用户。有没有办法只获取本地用户。
我要的是名字
您需要添加对 System.DirectoryServices
的引用才能使用此功能...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Users As List(Of String) = GetLocalUsers("localhost")
For Each User As String In Users
MessageBox.Show(User)
Next
End Sub
Private Function GetLocalUsers(ByVal MachineName As String) As List(Of String)
Dim WinNt As New DirectoryServices.DirectoryEntry("WinNT://" & MachineName)
Dim UserList As New List(Of String)
For Each User As DirectoryServices.DirectoryEntry In WinNt.Children
If User.SchemaClassName = "User" Then
UserList.Add(User.Name)
End If
Next
Return UserList
End Function
我需要获取所有本地用户的方法。如果我只是去用户文件夹病得到本地用户和域用户。有没有办法只获取本地用户。
我要的是名字
您需要添加对 System.DirectoryServices
的引用才能使用此功能...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Users As List(Of String) = GetLocalUsers("localhost")
For Each User As String In Users
MessageBox.Show(User)
Next
End Sub
Private Function GetLocalUsers(ByVal MachineName As String) As List(Of String)
Dim WinNt As New DirectoryServices.DirectoryEntry("WinNT://" & MachineName)
Dim UserList As New List(Of String)
For Each User As DirectoryServices.DirectoryEntry In WinNt.Children
If User.SchemaClassName = "User" Then
UserList.Add(User.Name)
End If
Next
Return UserList
End Function