×

managementobjectsearcher

如何用c# 获取cpu温度!?使用C#获取盘符

admin admin 发表于2022-05-09 13:17:53 浏览160 评论0

抢沙发发表评论

如何用c# 获取cpu温度!

ManagementObjectSearcher vManagementObjectSearcher = new ManagementObjectSearcher(@“root\WMI“, @“select * from MSAcpi_ThermalZoneTemperature“); foreach (ManagementObject vManagementObject in vManagementObjectSearcher.Get()) { //-2732再除以10 double temperature = double.Parse(vManagementObject.Properties[“CurrentTemperature“].Value.ToString()); temperature = (temperature - 2732) / 10; this.richTextBox1.Text=(temperature.ToString()); }

使用C#获取盘符

private void button1_Click(object sender, EventArgs e) { for (char c = ’a’; c 《= ’z’; c++) { try { DriveInfo drive = new DriveInfo(c + “:“); if (drive.DriveType == DriveType.Fixed) comboBox1.Items.Add(drive.Name); } catch (DriveNotFoundException dnf) { } } } 一个很SB的方法 可以看到所有固定磁盘 System.IO.Directory.GetLogicalDrives (); 返回的数组是当前已经使用的盘符,并非完全是固定磁盘(就是连CD光驱那些盘符都包括了)

C#用一个下拉列表,在里面显示所有电脑的盘符,急!~~~~

我给你一个最简单的:先创建一个comboBox然后在Form1_Load里输入this.comboBox1.DataSource =System.IO.Directory .GetLogicalDrives ();