fork(4) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Management;
  5. using System.Management.Instrumentation;
  6.  
  7. namespace temperature
  8. {
  9. class Program
  10. {
  11. const byte TEMPERATURE_HDD = 194;
  12. static public List<byte> GetDriveTemp()
  13. {
  14. List<byte> retval = new List<byte>();
  15. try
  16. {
  17. ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData");
  18. //loop through all the hard disks
  19. foreach (ManagementObject queryObj in searcher.Get())
  20. {
  21. byte[] arrVendorSpecific = (byte[])queryObj.GetPropertyValue("VendorSpecific");
  22. //Find the temperature attribute
  23. int tempIndex = Array.IndexOf(arrVendorSpecific, TEMPERATURE_HDD);
  24. retval.Add(arrVendorSpecific[tempIndex + 5]);
  25. }
  26. }
  27. catch (ManagementException err)
  28. {
  29. Console.WriteLine("An error occurred while querying for WMI data: " + err.Message);
  30. }
  31. return retval;
  32. }
  33.  
  34.  
  35. static void Main(string[] args)
  36. {
  37. List<byte> ls = GetDriveTemp();
  38. foreach (byte b in ls)
  39. Console.WriteLine(b);
  40.  
  41. }
  42. }
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Management' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(5,14): error CS0234: The type or namespace name `Management' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty