Utilizing Open {Hardware} Monitor Supply Code DLL With C#
Do you know that the Open {Hardware} Monitor DLL supplied with HWMonitor (OpenHardwareMonitorLib.dll) handles the entire heavy lifting inside the utility and can be utilized by builders to energy C#/.NET/ASP tasks 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 purposes in a couple of easy steps.

Earlier than we get began, let me introduce myself; I’m Andy, and I shall be your host for the subsequent ten minutes. For those who like, you may comply with me on Twitter the place I publish about my journey as a expertise author and a contract designer & developer.
You may like: Large Checklist of Free Overclocking Software program
First up, What’s HWMonitor?

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 comparable to CPU, RAM, GPU, Followers, onerous drives and even motherboard.
This utility is common amongst overclockers, avid gamers, pc {hardware} fans, 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, By way of & Intel Processors
- Assist for AMD, ATI & Nvidia GPUs
- Can report frequencies, voltages, temperature and extra.
- Continually up to date with contemporary {hardware} help
- Professional model consists of extra logging capabilities, distant operation, and graphing. (Not required for this text)
On the core, HWMonitor is getting all of its knowledge from the OpenHardwareMonitorLib.dll which is included inside the listing of the downloaded information. This single file is chargeable for the entire system well being statistics and system info reported inside the program – fortunate for us, we are able to take the DLL and use it in our personal tasks.
HWMonitor is obtainable for everybody to obtain from the CPUID obtain web page with no strings connected.
What System Data can I entry utilizing OpenHardwareMonitorLib.dll?
Now that you simply perceive HWMonitor and what its goal is, you may be 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 all the things 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 | Onerous Drives | S.M.A.R.T, SSD Put on Degree, Learn/Write |
6 | Followers | Fan Velocity |
For this text, I shall be specializing in fetching the CPU and GPU info, storing them in variables and outputting the values to the console. For those who want extra stats comparable to motherboard or ram, you should use the identical strategies to entry another system info you want.
Integrating the HWMonitor DLL with Visible Studio / C#
Earlier than you may question the DLL and begin fetching info in your C# code, that you must undergo some fundamental venture arrange to make sure you can entry Open {Hardware} Monitor from inside your venture.
Under is an summary of the steps required.
Steps Required
- Obtain Visible Studio
- Open Visible Studio
- Begin a New C# Venture
- Extract OpenHardwareMonitorLib.dll
- Add DLL to Visible Studio Venture
- Pressure your app to run in administrator mode
We could get began?
1. Obtain Visible Studio
Head over to the Visible Studio web site and obtain the related model. I’m utilizing MAC for programming atm so I downloaded that one.
2. Set up & Open Visible Studio

After 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, that you must arrange a brand new venture.
Comply with these easy steps to get began:
- Click on new
- Choose console venture
- After, choose .internet framework 5.0
- Give your venture a singular identify
- Allow GIT if you happen to want model management
- Click on the create button

Along with your C# venture arrange and able to go, that you must extract the required file and pull it into your venture. To do that, obtain HWMonitor, open the zip and transfer OpenHardwareMonitorLib.dll into your new c# venture folder.
5. Add DLL to Visible Studio Venture

To begin fetching the system info in our code, that you must add the DLL file reference to your visible studio c# venture.
Here’s what that you must do:
- Click on Venture > Add Reference
- Choose the .internet meeting tab, click on Browse
- Navigate to and choose the copy of OpenHardwareMonitorLib.dll that you simply positioned in your venture folder
- Hit okay
These important steps guarantee you’ve 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 comparable to CPU frequency, load and voltage, transfer on to the subsequent step beneath, which outlines some sensible examples.
6. Pressure your app to run in administrator mode
To entry system-level info, that you must full one last step designed to allow administrator entry at startup.
- From the venture panel, proper click on Venture > Add New and click on Software Manifest File
- Press Ctrl + Shift + F and seek for “requestedExecutionLevel”
- Change the tag to:
Failure to finish these last steps will lead to clean knowledge 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 utility 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 through the Gist.
Earlier than you should use this instance code, you will have to arrange a brand new venture which I outlined within the earlier step.
Breaking down the Code

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 all the things is working.
1. Embrace 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 prime of your venture principal 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. All the things we’d like is held inside the pc object, and it’s also the place we outline which {hardware} we wish 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 knowledge for any processors or graphics playing cards at present related to the system. If we don’t outline them right here, we received’t have any knowledge inside the loop.
In case you’re questioning, here’s a listing of the choices accessible to the item: new Laptop(){}
.
Full Checklist of {Hardware} Stories Accessible
- GPUEnabled – Allow GPU associated statistics and studies
- CPUEnabled – Allow CPU associated statistics and studies
- RAMEnabled – Allow RAM associated statistics and studies
- MainboardEnabled – Allow Motherboard associated statistics and studies
- FanControllerEnabled – Allow Fan associated statistics and studies
- HDDEnabled – Allow Onerous 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 is named each second by the Important methodology positioned on the backside of the file. This loop makes a name to ReportSystemInfo()
, which works by all of the accessible knowledge 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 Kind and Sensor Title.
4. Accessing CPU Data
Contained in the loop, there are two distinct sections masking CPU info and the opposite masking the GPU. Right here we’ll look particularly on the CPU.
5. Accessing GPU Data
After the CPU part, you can see yet one more part masking 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.
Conclusion
This has been fairly a prolonged tutorial. For those who adopted alongside and managed to get all the things working, pat your self on the again.
The Open {Hardware} Library allows .internet and c# builders to interface with system {hardware} and fetch key info on a variety of {hardware} sensors. This methodology might pave the best way for distinctive purposes which can be decoupled from the HWMonitor UI. This can allow builders comparable to your self to simply create their system well being displays and laptop well being standing displays.