One of the ways is with WMI (Win32_UserAccount)
that you can filter for example from Disabled field
Getting a list of user profile paths on a computer
Darren Rose
281
Reputation points
Hi
I am trying to obtain a list of all user profile paths on a machine - just those which are real users so excluding ones like default, public, network services etc
I can do it successfully by iterating HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList as per code below
Just wondered it anyone has a better method, or if there is some built in .NET command / function to do this
Thanks
Public Class Form1
Dim paths As New List(Of String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim registrypath As Microsoft.Win32.RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64)
Using key = registrypath.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each subKeyName In key.GetSubKeyNames()
Using subKey = key.OpenSubKey(subKeyName, True) ' true so opened as writable if not get UnauthorizedAccessException below
If subKey.GetValue("FullProfile") IsNot Nothing Then
If subKey.GetValue("FullProfile").Equals(1) Then
paths.Add(subKey.GetValue("ProfileImagePath"))
End If
End If
End Using
Next
End Using
Stop
End Sub
End Class
3 answers
Sort by: Most helpful
-
Castorix31 85,881 Reputation points
2020-12-02T15:21:43.02+00:00 -
RLWA32 45,701 Reputation points
2020-12-02T15:50:02.49+00:00 And also from WMI Win32_UserProfile class
-
Darren Rose 281 Reputation points
2020-12-02T19:34:58.117+00:00 Thank you both that is handy to know, not sure if WMI is better than what I am currently doing though