using System; using Microsoft.VisualBasic; using System.Collections.Generic; using System.Management; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HDDReader { class Program { static void Main(string[] args) { // Try/Catch all possible errors during the process (You might want to catch specific errors down the line, but this can help debug immediate problems try { // Create a new container for our drives List Drives = new List(); // Get Drives from WMI ManagementScope scope = new ManagementScope(@"root\wmi"); ObjectQuery query = new ObjectQuery("SELECT * FROM HDSentinel"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); // Iterate through drives from WMI int iterator = 0; foreach (ManagementObject eachObject in searcher.Get()) { // Add a new element to the list for each drive in WMI Drives.Add(new Drive()); // Functions seperated to make it easier to read Drives[iterator].InitValues( eachObject.GetPropertyValue("ModelID").ToString().Trim(), eachObject.GetPropertyValue("SerialNumber").ToString().Trim(), eachObject.GetPropertyValue("FirmwareRevision").ToString().Trim(), eachObject.GetPropertyValue("Interface").ToString().Trim(), eachObject.GetPropertyValue("PowerOnTime").ToString().Trim() ); Drives[iterator].PopulateData( eachObject.GetPropertyValue("PowerOnHours").ToString().Trim(), eachObject.GetPropertyValue("StartStopCount").ToString().Trim(), eachObject.GetPropertyValue("BadSectorCount").ToString().Trim(), eachObject.GetPropertyValue("WeakSectorCount").ToString().Trim(), eachObject.GetPropertyValue("SpinRetryCount").ToString().Trim(), eachObject.GetPropertyValue("CommunicationIssueCount").ToString().Trim(), eachObject.GetPropertyValue("StatusCode").ToString().Trim(), eachObject.GetPropertyValue("TRIMStatus").ToString().Trim() ); Drives[iterator].PopulateReport( eachObject.GetPropertyValue("Report").ToString().Trim(), eachObject.GetPropertyValue("TemperatureC").ToString().Trim(), eachObject.GetPropertyValue("Health").ToString().Trim(), eachObject.GetPropertyValue("Performance").ToString().Trim(), eachObject.GetPropertyValue("LifetimeWriteMB").ToString().Trim(), eachObject.GetPropertyValue("SMART").ToString().Trim() ); // Increment Iterator for accessing list iterator++; } // Iterate through Array of Hard Drives for (int i = 0; i < Drives.Count; i++) { // Check if drive was initialized (Happens during InitValues) if (Drives[i].Initialized) { // Make header, print report function, then print 2 newlines Console.WriteLine("--------- DRIVE #" + i + " -------------"); Drives[i].PrintReport(); Console.WriteLine("\n"); } } // Wait for user input before closing Console.ReadLine(); } // Catch Everything catch (Exception e) { Console.WriteLine("Error Detected: " + e.Message); Console.ReadLine(); } } } }