In fact, some information can be obtained without any P / Invoke.
Environment class:
Console.WriteLine("OS version: " + Environment.OSVersion.ToString()); Console.WriteLine("Processor count: " + Environment.ProcessorCount.ToString());
HKLM \ Hardware registry branch:
using Microsoft.Win32; //... object result = Registry.GetValue( "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "ProcessorNameString", ""); if (result != null) Console.WriteLine("Processor name: " + (result).ToString()); result = Registry.GetValue( "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "~MHz", 0); if (result != null) { Console.WriteLine("Processor frequency: " + ((int)result).ToString()+" MHz"); } result = Registry.GetValue( "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS" , "BaseBoardManufacturer", ""); if (result != null) Console.WriteLine("Motherboard vendor: " + (result).ToString()); result = Registry.GetValue( "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS" , "BaseBoardProduct", 0); if (result != null) Console.WriteLine("Motherboard name: " + (result).ToString());
But most of the information about devices is in the SMBIOS table, which can be obtained using the GetSystemFirmwareTable function (indeed, from kernel32.dll):
[DllImport("kernel32.dll")] public static extern uint GetSystemFirmwareTable( uint FirmwareTableProviderSignature, uint FirmwareTableID, [Out, MarshalAs(UnmanagedType.LPArray)] byte[] pFirmwareTableBuffer, uint BufferSize); // ... byte[] arr = new byte[5000]; uint sig = 0x52534D42;//RSMB uint res = GetSystemFirmwareTable(sig, 0, arr, 5000); if (res == 0 || res > 5000) { throw new ApplicationException("GetSystemFirmwareTable failed"); }
The structure of the SMBIOS table is described in the specification: https://www.dmtf.org/standards/smbios
An example of retrieving information about hardware in the C language can be found here . Also, there is a C # SMBIOS parser code under the MPL license.