Control the CPU fan in C #

13

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

I tried to use this code but I did not get results either.

[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: WMI and Open Hardware Monitor , but I have not found any examples of how I can apply.

Does anyone have any idea how I can do this?

    
asked by anonymous 13.12.2013 / 11:44

1 answer

9

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

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

If this method was implemented the code to call 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"]);
        }
    }
}

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

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

Code based in this example .

EDITION:

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

    
13.12.2013 / 13:07