' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
﻿Imports System
Imports System.IO
Imports System.Management

Imports Microsoft.Win32

Namespace E
    Public Class Program
        Public Shared Sub Main(args As String())
            Dim profiles As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("ProfileList")
            For Each sid As String In profiles.GetSubKeyNames()
                If Directory.Exists(DirectCast(profiles.OpenSubKey(sid).GetValue("ProfileImagePath"), String)) Then
                    Dim acct As New ManagementObject(New ManagementScope("\\.\ROOT\cimv2"), New ManagementPath("Win32_SID.SID='" & sid & "'"), New ObjectGetOptions())
                    Console.WriteLine(Convert.ToString(acct("ReferencedDomainName")) & "\" & Convert.ToString(acct("AccountName")))
                End If
            Next
        End Sub
    End Class
End Namespace
