Control the CPU fan in C#

How do I read and set the CPU fan speed and also read the current speed?

I tried to use this code but also could not get result.

[DllImport("Cimwin32.dll")]
static extern uint32 SetSpeed(in uint64 sp);

private void button1_Click(object sender, EventArgs e)
{
           SetSpeed(300);
}

I saw that there are two classes I can use: the WMIand the Open Hardware Monitor, but I did not find any examples of how I do to apply.

Anyone have any idea how I can do this?

 13
Author: Alexandre Marcondes, 2013-12-13

1 answers

This DLL does not have this call, so this way will fail when searching for this name in the library.

According to the Microsoft documentation this method is not implemented by WMI.

If this method were implemented the code to call it, it would be this:

using System;
using System.Text;
using System.Management;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementClass fanClass = new ManagementClass("CIM_Fan");

            ManagementBaseObject inParams = fanClass.GetMethodParameters("SetSpeed");
            inParams["DesiredSpeed"] = 1000;

            ManagementBaseObject outParams = fanClass.InvokeMethod("SetSpeed", inParams, null);

            Console.WriteLine("SetSpeed to 1000. returned: " + outParams["returnValue"]);
        }
    }
}

But the code fails to execute the InvokeMethod method because the method is not implemented.

Remembering to include an assembly reference in the project for System.Management.

Code based on this example .

Edition:

It seems that it is not possible without writing a driver for Windows, according to this question in the OS .

 9
Author: Vargas, 2017-05-23 12:37:33