Hardware.Info 10.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Hardware.Info --version 10.1.1                
NuGet\Install-Package Hardware.Info -Version 10.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hardware.Info" Version="10.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hardware.Info --version 10.1.1                
#r "nuget: Hardware.Info, 10.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hardware.Info as a Cake Addin
#addin nuget:?package=Hardware.Info&version=10.1.1

// Install Hardware.Info as a Cake Tool
#tool nuget:?package=Hardware.Info&version=10.1.1                

Hardware.Info

Battery, BIOS, CPU - processor, storage drive, keyboard, RAM - memory, monitor, motherboard, mouse, NIC - network adapter, printer, sound card - audio card, graphics card - video card. Hardware.Info is a .NET Standard 2.0 library and uses WMI on Windows, /dev, /proc, /sys on Linux and sysctl, system_profiler on macOS.

How to use:

  1. Include NuGet package from https://www.nuget.org/packages/Hardware.Info

     <ItemGroup>
         <PackageReference Include="Hardware.Info" Version="10.1.1.0" />
     </ItemGroup>
    
  2. Call RefreshAll() or one of the other Refresh*() methods:

     class Program
     {
         static readonly IHardwareInfo hardwareInfo = new HardwareInfo();
    
         static void Main(string[] _)
         {
             //hardwareInfo.RefreshOperatingSystem();
             //hardwareInfo.RefreshMemoryStatus();
             //hardwareInfo.RefreshBatteryList();
             //hardwareInfo.RefreshBIOSList();
             //hardwareInfo.RefreshCPUList();
             //hardwareInfo.RefreshDriveList();
             //hardwareInfo.RefreshKeyboardList();
             //hardwareInfo.RefreshMemoryList();
             //hardwareInfo.RefreshMonitorList();
             //hardwareInfo.RefreshMotherboardList();
             //hardwareInfo.RefreshMouseList();
             //hardwareInfo.RefreshNetworkAdapterList();
             //hardwareInfo.RefreshPrinterList();
             //hardwareInfo.RefreshSoundDeviceList();
             //hardwareInfo.RefreshVideoControllerList();
    
             hardwareInfo.RefreshAll();
    
             Console.WriteLine(hardwareInfo.OperatingSystem);
    
             Console.WriteLine(hardwareInfo.MemoryStatus);
    
             foreach (var hardware in hardwareInfo.BatteryList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.BiosList)
                 Console.WriteLine(hardware);
    
             foreach (var cpu in hardwareInfo.CpuList)
             {
                 Console.WriteLine(cpu);
    
                 foreach (var cpuCore in cpu.CpuCoreList)
                     Console.WriteLine(cpuCore);
             }
    
             Console.ReadLine();
    
             foreach (var drive in hardwareInfo.DriveList)
             {
                 Console.WriteLine(drive);
    
                 foreach (var partition in drive.PartitionList)
                 {
                     Console.WriteLine(partition);
    
                     foreach (var volume in partition.VolumeList)
                         Console.WriteLine(volume);
                 }
             }
    
             Console.ReadLine();
    
             foreach (var hardware in hardwareInfo.KeyboardList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.MemoryList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.MonitorList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.MotherboardList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.MouseList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.NetworkAdapterList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.PrinterList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.SoundDeviceList)
                 Console.WriteLine(hardware);
    
             foreach (var hardware in hardwareInfo.VideoControllerList)
                 Console.WriteLine(hardware);
    
             Console.ReadLine();
    
             foreach (var address in HardwareInfo.GetLocalIPv4Addresses(NetworkInterfaceType.Ethernet, OperationalStatus.Up))
                 Console.WriteLine(address);
    
             Console.WriteLine();
    
             foreach (var address in HardwareInfo.GetLocalIPv4Addresses(NetworkInterfaceType.Wireless80211))
                 Console.WriteLine(address);
    
             Console.WriteLine();
    
             foreach (var address in HardwareInfo.GetLocalIPv4Addresses(OperationalStatus.Up))
                 Console.WriteLine(address);
    
             Console.WriteLine();
    
             foreach (var address in HardwareInfo.GetLocalIPv4Addresses())
                 Console.WriteLine(address);
    
             Console.ReadLine();
         }
     }
    

Known issues

21 second delay on first use in Windows

Hardware.Info uses WMI (Windows Management Instrumentation) on Windows OS. For certain queries WMI takes 21 seconds to initialize the first time you use it, after that all subsequent queries will execute immediately. If WMI isn't used for 15 minutes it will have to be initialized again the next time you use it.

The 21 second initialization delay is caused by RPC that WMI uses internally. In RPC documentation it says that the RPC/TCP time-out interval is defined with a SCMApiConnectionParam registry value located at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control and that the default value is set to 21,000 (21 seconds).

You can avoid the 21 second delay by excluding the queries that cause it (see Settings).

Settings

Constructor settings:

HardwareInfo(bool useAsteriskInWMI = true, TimeSpan? timeoutInWMI = null)

The construcotr accepts two settings for WMI:

  • useAsteriskInWMI causes WMI queries to use SELECT * FROM instead of SELECT with a list of property names. This is slower, but safer, more compatible with older Windows (XP, Vista, 7, 8) where a certain WMI property might be missing and throw an exception when queried by name. The default value is true.
  • timeoutInWMI sets the Timeout property of the EnumerationOptions in the ManagementObjectSearcher that executes the query. The default value is EnumerationOptions.InfiniteTimeout. Changing this could cause the query to return empty results in certain cases.

Refresh methods settings:

In these two methods you can exclude some slow queries by setting the parameters to false:

RefreshCPUList(bool includePercentProcessorTime = true)

RefreshNetworkAdapterList(bool includeBytesPersec = true, bool includeNetworkAdapterConfiguration = true)

Setting includePercentProcessorTime and includeBytesPersec to false will exclude the queries that:

  • cause a 21 second delay the first time they are called in Windows
  • cause a 1 second delay every time they are called in Linux

Setting includeNetworkAdapterConfiguration to false has only a small impact on performance.

Benchmarks

Windows 8.1 (Intel i5-2500, 8 GB RAM):

Method Mean Error StdDev
RefreshMemoryStatus 947.8 ns 3.77 ns 3.53 ns
RefreshBatteryList 1,811,885.7 ns 12,921.05 ns 11,454.17 ns
RefreshBIOSList 2,086,001.0 ns 23,896.69 ns 22,352.98 ns
RefreshCPUList 1,543,579,005.2 ns 2,405,376.47 ns 2,132,303.59 ns
RefreshDriveList 409,137,516.3 ns 8,612,410.99 ns 25,258,710.57 ns
RefreshKeyboardList 5,568,039.5 ns 44,228.57 ns 41,371.43 ns
RefreshMemoryList 2,120,024.5 ns 26,103.39 ns 24,417.13 ns
RefreshMonitorList 5,669,237.8 ns 50,801.76 ns 45,034.44 ns
RefreshMotherboardList 1,965,222.9 ns 14,387.30 ns 13,457.89 ns
RefreshMouseList 6,003,924.9 ns 60,725.05 ns 50,708.17 ns
RefreshNetworkAdapterList 1,412,244,738.6 ns 14,681,615.28 ns 12,259,813.69 ns
RefreshPrinterList 28,244,822.2 ns 143,359.60 ns 134,098.66 ns
RefreshSoundDeviceList 3,608,577.5 ns 68,688.62 ns 73,496.06 ns
RefreshVideoControllerList 11,568,549.2 ns 54,666.07 ns 48,460.05 ns

Windows 10 (AMD Ryzen 5 5600G, 32 GB RAM):

Method Mean Error StdDev
RefreshOperatingSystem 2.946 ns 0.0052 ns 0.0047 ns
RefreshMemoryStatus 460.552 ns 4.4810 ns 3.9723 ns
RefreshBatteryList 1,624,392.057 ns 22,526.9314 ns 21,071.7057 ns
RefreshBIOSList 1,785,673.828 ns 8,812.8115 ns 8,243.5094 ns
RefreshCPUList 1,964,995,539.000 ns 171,465,934.5051 ns 505,571,176.5574 ns
RefreshDriveList 62,452,668.148 ns 342,662.0413 ns 320,526.2860 ns
RefreshKeyboardList 4,303,528.516 ns 47,355.1733 ns 41,979.1277 ns
RefreshMemoryList 1,926,931.367 ns 19,754.4179 ns 18,478.2948 ns
RefreshMonitorList 3,884,362.370 ns 29,422.1438 ns 27,521.4916 ns
RefreshMotherboardList 1,782,235.664 ns 12,974.2296 ns 12,136.1024 ns
RefreshMouseList 4,700,086.615 ns 44,435.0631 ns 41,564.5856 ns
RefreshNetworkAdapterList 945,004,493.333 ns 8,568,978.4607 ns 8,015,427.7687 ns
RefreshPrinterList 48,126,103.030 ns 729,958.0933 ns 682,803.2534 ns
RefreshSoundDeviceList 4,154,082.924 ns 46,922.5501 ns 41,595.6184 ns
RefreshVideoControllerList 8,784,372.500 ns 125,080.5212 ns 117,000.3971 ns

Version history:

  • 10.1.1.0:
    • Fixed GetCpuUsage in Linux - thanks to @glebov21
  • 10.1.0.1:
  • 10.1.0.0:
    • Fixed PercentProcessorTime in Windows - thanks to @C6OI
  • 10.0.1.1:
    • Added GetOperatingSystem() in Windows, macOS, Linux - thanks to @adhip94
  • 10.0.1.0:
  • 10.0.0.1:
  • 10.0.0.0:
    • Fixed GetDriveList() and GetMemoryList() in Linux - thanks to @misaka00251
  • 1.1.1.1:
    • Added Memory.BankLabel, Memory.MinVoltage, Memory.MaxVoltage in Windows - by @AathifMahir
    • Added CPU.SocketDesignation, CPU.SecondLevelAddressTranslationExtensions in Windows - by @AathifMahir
    • Added Windows version check for WMI properties that require at least Windows 8
    • Added Windows version check for WMI properties that require at least Windows 10
    • Added XML summary for public properties in every class.
  • 1.1.1.0:
    • Added IHardwareInfo so that HardwareInfo can be mocked - by @240026763
  • 1.1.0.1:
    • Added two settings for WMI queries in Windows
    • Added three settings to exclude slow queries in Windows, macOS, Linux
  • 1.1.0.0:
    • Fixed reading MemAvailable instead of MemFree in Linux - by @schotime
  • 1.0.1.1:
    • Added CpuCore info in Linux - by @isenmann
    • Added CPU.PercentProcessorTime, CPU.CpuCoreList in Linux - by @isenmann
  • 1.0.1.0:
    • Added CpuCore info in Windows - by @isenmann
    • Added CPU.PercentProcessorTime, CPU.CpuCoreList in Windows - by @isenmann
    • Added NetworkAdapter.BytesSentPersec, NetworkAdapter.BytesReceivedPersec in Windows - by @isenmann
  • 1.0.0.1:
    • Added Battery.EstimatedChargeRemaining in Windows, Linux - by @reptail
  • 1.0.0.0:
    • Added Battery.ExpectedLife in Linux
    • Added Battery.EstimatedRunTime in Linux
    • Added Battery.MaxRechargeTime in Linux
    • Added Battery.TimeToFullCharge in Linux
  • 0.1.1.1:
    • Added Battery.DesignCapacity in Linux
    • Added Battery.FullChargeCapacity in Linux
  • 0.1.1.0:
    • Added Battery.BatteryStatusDescription in Linux
  • 0.1.0.1:
    • Added Monitor info in macOS
    • Added VideoController info in macOS
  • 0.1.0.0:
    • Added CPU.L2CacheSize in macOS
    • Added CPU.L3CacheSize in macOS
    • Added Memory info in macOS
  • 0.0.1.1:
    • Added BIOS.ReleaseDate in Linux
    • Added CPU.Manufacturer in Linux
    • Added CPU.L3CacheSize in Linux
    • Added Motherboard.SerialNumber in Linux
    • Fixed NetworkAdapter info in Linux
    • Fixed GetLocalIPv4Addresses() in macOS
  • 0.0.1.0:
    • Added GetLocalIPv4Addresses() in Windows, macOS, Linux
    • Added Motherboard.SerialNumber in Windows
    • Added Drive, NetworkAdapter info in macOS, Linux
  • 0.0.0.1:
    • All hardware info in Windows
    • CPU, RAM info in macOS, Linux
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (18)

Showing the top 5 NuGet packages that depend on Hardware.Info:

Package Downloads
HexaEightJWTLibrary

Create and Validate HexaEight JWT Tokens using this Libarary. This Library provides helper functions to implement HexaEight authenticated encryption and decryption of messages.

PGCG.commonItems

Package Description

Jakar.Database

Package Description

MarkopTest

Merkop Test is a free, open source, focused testing tool for the ASP.NET Framework.

OneStream.Common

Package Description

GitHub repositories (7)

Showing the top 5 popular GitHub repositories that depend on Hardware.Info:

Repository Stars
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
Stability-AI/StableSwarmUI
StableSwarmUI, A Modular Stable Diffusion Web-User-Interface, with an emphasis on making powertools easily accessible, high performance, and extensibility.
mcmonkeyprojects/SwarmUI
SwarmUI (formerly StableSwarmUI), A Modular Stable Diffusion Web-User-Interface, with an emphasis on making powertools easily accessible, high performance, and extensibility.
PixiEditor/PixiEditor
PixiEditor is a pixel art editor made with .NET 8
codeproject/CodeProject.AI-Server
CodeProject.AI Server is a self contained service that software developers can include in, and distribute with, their applications in order to augment their apps with the power of AI.
Version Downloads Last updated
101.0.0 200,748 9/19/2024
100.1.1.1 1,735 9/18/2024
100.1.1 69,069 8/29/2024
100.1.0.1 91,620 7/5/2024
100.1.0 91,548 3/2/2024
100.0.1.1 43,629 1/5/2024
100.0.1 7,361 12/8/2023
100.0.0.1 22,534 11/30/2023
100.0.0 16,802 9/17/2023
11.1.1.1 22,709 7/19/2023
11.1.1 1,620 7/16/2023
11.1.0.1 18,745 7/7/2023
11.1.0 10,042 5/19/2023
11.0.1.1 1,885 5/13/2023
11.0.1 9,150 4/22/2023
11.0.0.1 1,362 4/17/2023
11.0.0 12,481 3/25/2023
10.1.1.1 20,028 3/12/2023
10.1.1 87,126 1/13/2023
10.1.0.1 10,361 12/6/2022
10.1.0 25,862 10/15/2022
10.0.1.1 26,017 10/2/2022
10.0.1 39,115 6/4/2022
10.0.0.1 12,607 4/29/2022
10.0.0 40,887 2/3/2022
1.1.1.1 46,590 9/12/2021
1.1.1 1,468 8/25/2021
1.1.0.1 903 8/23/2021
1.1.0 1,755 8/7/2021
1.0.1.1 16,059 5/17/2021
1.0.1 1,065 4/27/2021
1.0.0.1 2,811 1/23/2021
1.0.0 1,837 12/19/2020
0.1.1.1 3,248 12/12/2020
0.1.1 1,009 12/6/2020
0.1.0.1 1,342 9/27/2020
0.1.0 1,150 9/13/2020
0.0.1.1 1,072 8/7/2020
0.0.1 1,051 7/29/2020
0.0.0.1 1,274 7/21/2020