VB Getting list of local users

元气小坏坏 提交于 2019-12-13 09:16:26

问题


I need way of getting all local users. If i just go to the users folder ill get the local users and the domain users. Is there a way to get only the local users.

What i want is the name.


回答1:


You need to add a reference to System.DirectoryServices to be able to use this function...

 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


来源:https://stackoverflow.com/questions/27993947/vb-getting-list-of-local-users

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!