Utilizing Open {Hardware} Monitor Supply Code DLL With C#


Do you know that the Open {Hardware} Monitor DLL supplied with HWMonitor (OpenHardwareMonitorLib.dll) handles all the heavy lifting inside the software and can be utilized by builders to energy C#/.NET/ASP initiatives with relative ease.

You possibly can merely copy this single file, drop it into your c# venture, add a reference and you can begin creating system well being functions in a couple of easy steps.

Open Hardware Monitor DLL with Visual Studio
Open {Hardware} Monitor DLL with Visible Studio

Earlier than we get began, let me introduce myself; I’m Andy, and I shall be your host for the subsequent ten minutes. If you happen to like, you may follow me on Twitter the place I put up about my journey as a know-how author and a contract designer & developer.

You may like: Huge List of Free Overclocking Software

First up, What’s HWMonitor?

CPUID HWMonitor Program
HWMonitor by CPUID

To first perceive the Open Hardware Monitor Libray, you first should perceive what HWMonitor does. HWMonitor is a system info & system well being monitoring software program for Home windows and Linux. This free system reporting software program shows info on a variety of your pc {hardware} sensors reminiscent of CPU, RAM, GPU, Followers, arduous drives and even motherboard.

This software is fashionable amongst overclockers, players, pc {hardware} fanatics, skilled pc technicians and, comes with a number of options that put it a step forward of the competitors for its reporting capabilities.

HWMonitor Key Options

  • Trusted inside the group
  • Assist for AMD, Through & Intel Processors
  • Assist for AMD, ATI & Nvidia GPUs
  • Can report frequencies, voltages, temperature and extra.
  • Continuously up to date with recent {hardware} assist
  • Professional model consists of further logging capabilities, distant operation, and graphing. (Not required for this text)

On the core, HWMonitor is getting all of its information from the OpenHardwareMonitorLib.dll which is included inside the listing of the downloaded information. This single file is accountable for all the system well being statistics and system info reported inside the program – fortunate for us, we will take the DLL and use it in our personal initiatives.

HWMonitor is obtainable for everybody to obtain from the CPUID download page with no strings hooked up.

What System Data can I entry utilizing OpenHardwareMonitorLib.dll?

Now that you simply perceive HWMonitor and what its function is, you is perhaps left with a query: what are you able to do with the Open {Hardware} Monitor DLL, and what info does it expose? Right here is every little thing I might discover.

# {Hardware} Data Accessible
1 CPU Bus Velocity, Frequency, Utilization, Temperature, Energy Draw
2 GPU Core Frequency, Reminiscence Frequency, GPU Utilization, Temperature
3 RAM Ram utilization
4 Motherboard Vcore, DRAM voltage, System Temperature, CPU Temperature
5 Laborious Drives S.M.A.R.T, SSD Put on Degree, Learn/Write
6 Followers Fan Velocity

For this text, I will probably be specializing in fetching the CPU and GPU info, storing them in variables and outputting the values to the console. If you happen to want extra stats reminiscent of motherboard or ram, you should use the identical strategies to entry some other system info you would like.

Integrating the HWMonitor DLL with Visible Studio / C#

Earlier than you may question the DLL and begin fetching info in your C# code, you want to undergo some fundamental venture arrange to make sure you can entry Open {Hardware} Monitor from inside your venture.

Beneath is an summary of the steps required.

Steps Required

  1. Obtain Visible Studio
  2. Open Visible Studio
  3. Begin a New C# Venture
  4. Extract OpenHardwareMonitorLib.dll
  5. Add DLL to Visible Studio Venture
  6. Drive your app to run in administrator mode

Lets get began?

1. Obtain Visible Studio

Head over to the Visible Studio web site and download the related model. I’m utilizing MAC for programming atm so I downloaded that one.

2. Set up & Open Visible Studio

Start a new projectt
Open Visible Studio

Upon getting downloaded Visible Studio, go forward and open the file to start out the set up. As soon as full go forward and open this system.

3. Begin a New C# Venture

Earlier than you can begin writing any code or interacting with HWMonitor, you want to arrange a brand new venture.

Comply with these easy steps to get began:

  1. Click on new
  2. Choose console venture
  3. After, choose .web framework 5.0
  4. Give your venture a singular identify
  5. Allow GIT when you want model management
  6. Click on the create button
HWMonitor DLL
Begin a brand new venture

Together with your C# venture arrange and able to go, you want to extract the required file and pull it into your venture. To do that, download HWMonitor, open the zip and transfer OpenHardwareMonitorLib.dll into your new c# venture folder.

5. Add DLL to Visible Studio Venture

HWmonitor c# reference
Reference the Open {Hardware} Monitor DLL

To begin fetching the system info in our code, you want to add the DLL file reference to your visible studio c# venture.

Here’s what you want to do:

  1. Click on Venture > Add Reference
  2. Choose the .web meeting tab, click on Browse
  3. Navigate to and choose the copy of OpenHardwareMonitorLib.dll that you simply positioned in your venture folder
  4. Hit okay

These vital steps guarantee you might have added the required DLL file to the venture and that you would be able to now reference it in your venture’s information. To learn the way to probe your system and pull important info reminiscent of CPU frequency, load and voltage, transfer on to the subsequent step under, which outlines some sensible examples.

6. Drive your app to run in administrator mode

To entry system-level info, you want to full one ultimate step designed to allow administrator entry at startup.

  1. From the venture panel, proper click on Venture > Add New and click on Software Manifest File
  2. Press Ctrl + Shift + F and seek for “requestedExecutionLevel”
  3. Change the tag to:

Failure to finish these ultimate steps will lead to clean information being returned from OpenHardwareMonitorLib.dll. Sadly, I made this error in my venture and spent ages debugging.

Instance Code: OpenHardwareMonitorLib.dll and C#

The above instance will get you up and going with an precise software that grabs details about your pc’s CPU and GPU and outputs them to a easy console app. In order for you, you may seize this code by way of the Gist.

Earlier than you should use this instance code, you will have to arrange a brand new venture which I outlined in the previous step.

Breaking down the Code

Open Hardware Monitor code breakdown

The above code is a wonderful copy and paste instance for knowledgeable builders who know their means round however, for these of you with rather less programming expertise, this part was made for you.

I’ll break down the instance code and present you step-by-step how every little thing is working.

1. Embody a Reference to the DLL

To begin and, earlier than you may entry the {hardware} studies you want, you’ll first want to incorporate a reference to the DLL on the high of your venture predominant file proper after the opposite utilizing statements.

This line of code will allow Visible Studio to entry the performance we’d like in additional steps. Allow us to transfer on.

2. Defining the {Hardware} to Report

To begin grabbing laptop well being stats, we have to outline a brand new pc object uncovered by the Open {Hardware} Monitor DLL. The whole lot we’d like is held inside the pc object, and it is usually the place we outline which {hardware} we would like laptop well being stats reported for.

You’ll discover two settings inside our new pc object; GPUEnabled = true and CPUEnabled = true. These settings inform the Open {Hardware} Monitor library to return information for any processors or graphics playing cards at present related to the system. If we don’t outline them right here, we gained’t have any information inside the loop.

In case you’re questioning, here’s a checklist of the choices out there to the thing: new Laptop(){}.

Full Listing of {Hardware} Stories Accessible

  1. GPUEnabled – Allow GPU associated statistics and studies
  2. CPUEnabled – Allow CPU associated statistics and studies
  3. RAMEnabled – Allow RAM associated statistics and studies
  4. MainboardEnabled – Allow Motherboard associated statistics and studies
  5. FanControllerEnabled – Allow Fan associated statistics and studies
  6. HDDEnabled – Allow Laborious Drive associated statistics and studies

Now, contemplating we’ve got outlined the pc object, we have to begin a connection between your code and the DLL file.

This single line will startup the DLL and allow it to start out fetching laptop well being standing.

3. The Loop

The loop is the place the magic occurs and known as each second by the Major methodology positioned on the backside of the file. This loop makes a name to ReportSystemInfo(), which works via all of the out there information and returns solely the data we’ve got requested.

As you may see, strategies are comparatively straight ahead and it’s so simple as focusing on the right Sensor Sort and Sensor Identify.

4. Accessing CPU Data

Contained in the loop, there are two distinct sections overlaying CPU info and the opposite overlaying the GPU. Right here we’ll look particularly on the CPU.

5. Accessing GPU Data

After the CPU part, you can find another part overlaying system info for each Nvidia and AMD GPUs. The Open {Hardware} Monitor library studies info for each individually, so we have to entry them of their distinctive means.


This has been fairly a prolonged tutorial. If you happen to adopted alongside and managed to get every little thing working, pat your self on the again.

The Open {Hardware} Library allows .web and c# builders to interface with system {hardware} and fetch key info on a variety of {hardware} sensors. This methodology might pave the way in which for distinctive functions which are decoupled from the HWMonitor UI. It will allow builders reminiscent of your self to simply create their system well being displays and laptop well being standing displays.

Source link


Please enter your comment!
Please enter your name here