HI guys. I have a piece of code to find the temperature of a computer but I just cannot understand it. Could someone help in explaining this piece of code to me and also why it is finding the temperature for some operating systems and others it is returning an error?
Code:using System.Management; // Need to add reference System.Management .... string strsearch=string.Format(@"Select * from MSAcpi_ThermalZoneTemperature"); System.Management.ManagementObjectSearcher p_objSet=new ManagementObjectSearcher(); p_objSet.Scope=new ManagementScope(@"root\wmi"); p_objSet.Query=new ObjectQuery(strsearch); try { foreach(System.Management.ManagementObject objItem in p_objSet.Get()) { int RawData=Convert.ToInt32(objItem["CurrentTemperature"]); RawData = (RawData-2732)/10; txtCpu.Text = string.Format(RawData.ToString()); }// end foreach }// end try catch(ManagementException ee) { MessageBox.Show("ERROR: \r\n\r\n" +ee.Message); }// end try catch
Thanks - Jennifer




Reply With Quote