🟣 C# / .NET 6+
Get Local User Accounts Report (C#)
Queries Win32_UserAccount via WMI (System.Management) and prints Local User Accounts to the console.
GetUserAccountReport.cs
// GetUserAccountReport.cs
//
// Reports Local User Accounts via WMI (Win32_UserAccount).
//
// Requires the System.Management package:
// dotnet new console -o UserAccountReport
// dotnet add package System.Management
// (replace the generated Program.cs with this file, then dotnet run)
// On .NET Framework, System.Management is already available — just
// add a reference to it in your project.
using System;
using System.Management;
var searcher = new ManagementObjectSearcher("SELECT Name, FullName, Disabled, Lockout, LocalAccount FROM Win32_UserAccount");
int count = 0;
foreach (ManagementObject item in searcher.Get())
{
Console.WriteLine($"Name: {item["Name"]}");
Console.WriteLine($"FullName: {item["FullName"]}");
Console.WriteLine($"Disabled: {item["Disabled"]}");
Console.WriteLine($"Lockout: {item["Lockout"]}");
Console.WriteLine($"LocalAccount: {item["LocalAccount"]}");
Console.WriteLine(new string('-', 40));
count++;
}
if (count == 0)
{
Console.WriteLine("No Local User Accounts found.");
}
else
{
Console.WriteLine($"\n{count} Local User Accounts found.");
}