Control the fan (fan) of the CPU in C#

Asked

Viewed 300 times

13

How do I read and set the fan speed (fan) of the CPU 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 WMI and the Open Hardware Monitor, but I haven’t found any example of how to apply.

Does anyone have any idea how I can do this?

1 answer

9

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

According to the documentation of Microsoft 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 method InvokeMethod because the method is not implemented.

Recalling that it is necessary 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 the OS.

  • The same mistake happened to me. You know another way to try to control Fan by c#?

  • I edited the answer, it doesn’t seem possible without writing a driver =/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.