im使用OpenHardwareMonitor.Hardware dll跟踪gpu传感器,但无法获得风扇速度。请帮忙。
private void Get_GPU_Configuration()
{
try
{
Computer _comp = new Computer();
_comp.GPUEnabled = true;
_comp.Open();
dgv_Main_Window.Rows.Clear();
foreach (var hardwareItem in _comp.Hardware)
{
if ((hardwareItem.HardwareType == HardwareType.GpuAti) || (hardwareItem.HardwareType == HardwareType.GpuNvidia))
{
int index = dgv_Main_Window.Rows.Add();
string _device_Name = hardwareItem.Name.Trim();// Radeon(TM) R5 M430
hardwareItem.Update();
dgv_Main_Window.Rows[index].Cells[int_Device].Value = _device_Name;
foreach (var sensor in hardwareItem.Sensors)
{
string str = sensor.SensorType.ToString();
if (str == "Temperature")
{
dgv_Main_Window.Rows[index].Cells[int_Temperature].Value = sensor.Value.ToString();
}
if (str == "Clock")
{
if (sensor.Name == "GPU Core")
{
dgv_Main_Window.Rows[index].Cells[int_CoreClock].Value = sensor.Value.ToString();
}
else
{
dgv_Main_Window.Rows[index].Cells[int_MemoryClock].Value = sensor.Value.ToString();
}
}
if (str == "Fan")
{
if (sensor.Name == "GPU Fan")
{
dgv_Main_Window.Rows[index].Cells[int_FanSpeed].Value = sensor.Value;
}
}
}
string[] _deviceName_Array = new string[dgv_Main_Window.Rows.Count];
foreach (DataGridViewRow _drow in dgv_Main_Window.Rows)
{
int i = 0;
_deviceName_Array[i] = _drow.Cells[int_Device].Value.ToString();
i++;
}
ManagementScope ms = new ManagementScope(@"root\cimv2");
ObjectQuery oq2 = new ObjectQuery("select * from Win32_VideoController");
ManagementObjectSearcher _Video = new ManagementObjectSearcher(ms, oq2);
foreach (ManagementObject obj in _Video.Get())
{
foreach (PropertyData PC in obj.Properties)
{
}
foreach (var _data in _deviceName_Array)
{
if (_data == obj["Name"].ToString())
{
foreach (DataGridViewRow _drow in dgv_Main_Window.Rows)
{
if (_drow.Cells[int_Device].Value.ToString() == _data)
{
_drow.Cells[int_Id].Value = obj["DeviceID"].ToString();
_drow.Cells[int_Driver].Value = obj["DriverVersion"].ToString();
}
}
}
}
}
}
}
}
catch (Exception ex)
{
}
}
答案 0 :(得分:-1)
一个快速的谷歌,我找到了代码:
ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(@"root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature");
foreach (ManagementObject mo in mos.Get())
{
MessageBox.Show(((Convert.ToInt32(mo["CurrentTemperature"]) - 2732) / 10).ToString());
}
ManagementObjectSearcher mos1 = new System.Management.ManagementObjectSearcher(@"root\cimv2", "SELECT * FROM Win32_Fan");
foreach (ManagementObject mo in mos1.Get())
{
MessageBox.Show(mo["DesiredSpeed "].ToString());
}
问题是MoBo制造商有时不提供信息。如果此方法不起作用,或者您的解决方案不起作用,请检查主板的规格。