Your code can spy on its own host machine without a single line of P/Invoke.
The Environment class in .NET hands you the OS version, machine name, processor count, uptime, and more, all baked in. No WMI queries, no shelling out to PowerShell, no digging through the registry like it’s 1998.
Console.WriteLine($”OS: {Environment.OSVersion}”);
Console.WriteLine($”Machine Name: {Environment.MachineName}”);
Console.WriteLine($”Processor Count: {Environment.ProcessorCount}”); // <<< tells you how many cores you actually get to abuse
Console.WriteLine($”64-bit OS: {Environment.Is64BitOperatingSystem}”);It’s been quietly sitting in .NET since version 1.0 back in 2002, originally there so console apps could behave differently across Windows versions.
Microsoft basically built an entire class so you don’t have to open Task Manager like a caveman.
Try it yourself (no setup required): https://dotnetfiddle.net/jX9uiB


