龙空技术网

C# 获取电脑CPU温度与CPU处理器(WinForm)运行内存设备信息

快乐鲤渔 583

前言:

今天你们对“获取cpu信息”大约比较看重,你们都想要剖析一些“获取cpu信息”的相关内容。那么小编在网络上汇集了一些关于“获取cpu信息””的相关文章,希望咱们能喜欢,看官们快快来学习一下吧!

获取电脑CPU处理器硬件所有信息:

private void button1_Click(object sender, EventArgs e){    // 获取CPU处理器名称    ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");    foreach (ManagementObject obj in searcher.Get())    {        string cpuName = obj["Name"].ToString();        listBox1.Items.Add(cpuName);           }}private void button2_Click(object sender, EventArgs e){    // 获取内存卡名称              ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PhysicalMemory");    foreach (ManagementObject obj in searcher.Get())    {        string manufacturer = obj["Manufacturer"].ToString();        string capacity = obj["Capacity"].ToString();        long memorySizeBytes = Convert.ToInt64(capacity);        double memorySizeGB = memorySizeBytes / (1024 * 1024 * 1024.0);       //MessageBox.Show( "厂家名称:"+manufacturer+","+memorySizeGB.ToString("0.##") + " GB");        textBox2.Text = "厂家名称:"+ manufacturer +"\r\n" +"内存大小:" + memorySizeGB.ToString("0.##")+"GB";       // MessageBox.Show("Memory Size: " + memorySizeGB.ToString("0.##") + " GB");    }}private void button3_Click(object sender, EventArgs e){    // 获取硬盘设备名称    ManagementObjectSearcher driveSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive");    foreach (ManagementObject drive in driveSearcher.Get())    {        string driveName = drive["Caption"].ToString();        listBox2.Items.Add(driveName);                   }}private void button4_Click(object sender, EventArgs e){    // 获取CPU温度    ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature");    foreach (ManagementObject obj in searcher.Get())    {        double temperature = Convert.ToDouble(obj["CurrentTemperature"]) / 10 - 273.15;        textBox1.Text = temperature.ToString("0.##") + "°C";        textBox1.TextAlign = HorizontalAlignment.Center;    }}private void button5_Click(object sender, EventArgs e){    // 获取当前操作系统    ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");    ManagementObjectCollection results = searcher.Get();    foreach (ManagementObject os in results)    {        string osName = os["Caption"].ToString();        //Console.WriteLine("Operating System: " + osName);        textBox3.Text = osName;        textBox3.TextAlign = HorizontalAlignment.Center;    }   }

#头条创作挑战赛#

标签: #获取cpu信息