Here is a little function I put together that returns a list of all user account names on the specified computer.
You need to add a reference to System.DirectoryServices to be able to use this function.
Function:
vb Code:
''' <summary> ''' Returns a list of user accounts found on the specified computer ''' </summary> ''' <param name="MachineName">The computer to get user accounts from</param> 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
Example:
If you just want it to return the usernames on the local computer then just pass the string "localhost" in as the machine name, like so:
vb Code:
'Get the users, using our GetLocalUsers function Dim Users As List(Of String) = GetLocalUsers("localhost") 'loop through the users and show each user in a messagebox For Each User As String In Users MessageBox.Show(User) Next



Reply With Quote