VB Populate combo with Local Machine users

Michael 1 Reputation point
2022-08-23T12:20:54.49+00:00

I'm new to programming. I've tried using some older code a co-worker of mine made but his program has too many variables for my program to use it.

I'm trying to populate a combobox with all of the local machine users using the registry. Below is currently what I have.

Sub GetUserList(sKeyName As String)
Dim I, Idx As Integer
Dim SubKeyName As String

LUcombo.Items.Clear()  

Dim RegKey2 As RegistryKey = Registry.LocalMachine.OpenSubKey("software\microsoft\windows NT\CurrentVersion\ProfileList")  
Dim SubKeys() = RegKey2.GetSubKeyNames  

I = SubKeys.Length  
For Idx = 0 To I - 1  
    SubKeyName = SubKeys(Idx).ToString  
    If SubKeyName.Substring(0, 8) = "S-1-5-21" Then  
        LUcombo.Items.AddRange(SubKeys)  
    End If  
Next  

LUcombo.Text = "-Select User-"  

End Sub

Private Sub LUcombo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LUcombo.SelectedIndexChanged  
    GetUserList()  
End Sub
Developer technologies | VB
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 91,506 Reputation points
    2022-08-23T12:27:57.413+00:00

    Use rather WMI (Win32_UserAccount)
    (+ WMI Code Creator to generate VB code)


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.