static void Main() { // Write dependencies to disk // OpenHardwareMonitor is simply written to disk if not present if (!File.Exists("OpenHardwareMonitorLib.dll")) { WriteFile("OpenHardwareMonitorLib.dll", Properties.Resources.lib_hardware_monitor); } // An attempt to load SQLite, and if it fails, then write out the correct string architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"); try { Assembly.LoadFrom("System.Data.SQLite.dll"); } catch (Exception e) { // If the file was not found, or it was in the wrong architecture, then write the appropriate file if (e is BadImageFormatException || e is FileNotFoundException) { if (architecture == "AMD64") { // 64 bit WriteFile("System.Data.SQLite.dll", Properties.Resources.lib_sqlite_x64); } else { // 32 bit WriteFile("System.Data.SQLite.dll", Properties.Resources.lib_sqlite_x86); } } else { throw; } } // Run the program try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainWindow()); } catch (Exception e) { // Fatal unhandled error - report gracefully ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiDeviceMemoryAddress, ManagementObject wmiPnPEntity) { try { this.Device = DataRetriever.GetValue(wmiPnPEntity, "Name"); this.EndAddress = DataRetriever.GetValueUInt64(wmiDeviceMemoryAddress, "EndingAddress"); this.Resource = DataRetriever.GetValue(wmiDeviceMemoryAddress, "Description"); this.StartAddress = DataRetriever.GetValueUInt64(wmiDeviceMemoryAddress, "StartingAddress"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiBIOS) { try { this.Info = DataRetriever.GetValue(wmiBIOS, "Description"); this.SerialID = DataRetriever.GetValue(wmiBIOS, "SerialNumber"); // Get the version as an array of strings string[] versionTemp = DataRetriever.GetValueArray(wmiBIOS, "BIOSVersion"); // Join the pieces together for the string variable if (versionTemp != null) this.Version = String.Join(" - ", versionTemp); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
/// <summary> /// Special function for adding comments to the database /// </summary> /// <param name="comments">The comments to add.</param> /// <param name="id">The ID of the computer for which the comment belong.</param> /// <returns>True if the operation was successful, otherwise false.</returns> public static bool AddCommentsToDB(string comments, int id) { if (Connection != null && !abortOperation) { try { Connection.Open(); // If the database has been opened, continue if (Connection.State == ConnectionState.Open) { SQLiteCommand command = Connection.CreateCommand(); // Create a SQL statement to add values command.CommandText = "INSERT INTO comments VALUES('" + id + "','" + comments; command.CommandText += "')"; command.ExecuteNonQuery(); // End Connection.Close(); return true; } else { Connection.Close(); return false; } } catch (Exception e) { Connection.Close(); ErrorDialogue errorReporter = new ErrorDialogue(e); return false; } } else { return false; } }
// Main GetValue function - Converts the given Management data to a string // Handles errors in this process public static string GetValue(ManagementObject managementObject, string field) { try { return Convert.ToString(managementObject[field]); } catch(Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); return "0"; } }
public void GetInfo(ManagementObject wmiNetworkAdapter) { try { this.AdapterType = DataRetriever.GetValue(wmiNetworkAdapter, "AdapterType"); this.Availability = DataRetriever.ConvertAvailability(DataRetriever.GetValueUInt16(wmiNetworkAdapter, "Availability")); this.ErrorDescription = DataRetriever.GetValue(wmiNetworkAdapter, "ErrorDescription"); this.Manufacturer = DataRetriever.GetValue(wmiNetworkAdapter, "Manufacturer"); this.MACAddress = DataRetriever.GetValue(wmiNetworkAdapter, "MACAddress"); this.Name = DataRetriever.GetValue(wmiNetworkAdapter, "Caption"); this.PhysicalAdapter = DataRetriever.GetValueBool(wmiNetworkAdapter, "PhysicalAdapter"); this.Status = DataRetriever.GetValue(wmiNetworkAdapter, "Status"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiProduct) { try { this.Date = DataRetriever.GetValueDateString(wmiProduct, "InstallDate"); this.Name = DataRetriever.GetValue(wmiProduct, "Name"); this.Publisher = DataRetriever.GetValue(wmiProduct, "Vendor"); this.Version = DataRetriever.GetValue(wmiProduct, "Version"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiProcess) { try { this.ExecutablePath = DataRetriever.GetValue(wmiProcess, "ExecutablePath"); this.ImageName = DataRetriever.GetValue(wmiProcess, "Name"); this.Memory = DataRetriever.GetValueUInt64(wmiProcess, "VirtualSize"); this.PID = DataRetriever.GetValueUInt16(wmiProcess, "ProcessId"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiIRQResource, ManagementObject wmiPnPEntity) { try { this.Device = DataRetriever.GetValue(wmiPnPEntity, "Name"); this.Resource = DataRetriever.GetValue(wmiIRQResource, "Name"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
// A function to write files and provide an error if it doesn't go to plan private static void WriteFile(string path, byte[] bytes) { try { File.WriteAllBytes(path, bytes); } catch (Exception e) { if (e is IOException || e is UnauthorizedAccessException) { // Error dialogue allowing abort, retry and ignore DialogResult result = MessageBox.Show( "One of the required dependencies for Core View couldn't be loaded. " + "Please make sure the storage medium isn't write protected and dependency files are not in use.", "Unable to load dependency files", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error ); // Exit with error code 1 if aborted, retry this function if retry selected switch (result) { case DialogResult.Abort: Environment.Exit(1); break; case DialogResult.Retry: WriteFile(path, bytes); break; } } else { // Fatal error - report gracefully ErrorDialogue errorReporter = new ErrorDialogue(e); } } }
public static ManagementObject[] GetWMIReferences(string class1, string class2, string attribute, string value, string scope) { try { // Create a search query string query = "REFERENCES OF {" + class1 + "." + attribute + "='" + value + "'} " + "WHERE RESULTCLASS = " + class2; ManagementObjectSearcher wmiSearcher; if (scope != "") { // Scoped search wmiSearcher = new ManagementObjectSearcher("root\\" + scope, query); } else { // Unscoped search wmiSearcher = new ManagementObjectSearcher(query); } ManagementObjectCollection matches = wmiSearcher.Get(); // Create output array ManagementObject[] matchArray = new ManagementObject[matches.Count]; // If matches found, copy to output if (matches.Count > 0) { // Copy the search matches into this array matches.CopyTo(matchArray, 0); } else { // Return a single, null element if nothing is found matchArray = new ManagementObject[1] { null }; } return matchArray; } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); return null; } }
public void GetHardwareInfo() { // Complete error catching for information gathering try { // Hardware \\ // Output what the current task is doing // Add 3% onto progress bar // Each process will increate the percentage by a different amount // depending on how long it usually takes proportionally if (abortRetrieval) return; Splash.AddProgressInfo("Loading Processor Information...", 3); GetProcessors(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading Motherboard Information...", 2); GetMotherboards(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading BIOS Information...", 1); GetBIOS(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading Memory Information...", 2); GetMemory(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading Graphics Information...", 3); GetGraphics(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading Network Information...", 4); GetNetworks(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading Disk Drive Information...", 4); GetHardDrives(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading Optical Drive Information...", 2); GetOpticalDrives(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading PCI Information...", 4); GetPCICards(); if (abortRetrieval) return; Splash.AddProgressInfo("Loading USB Information...", 5); GetUSBDevices(); } catch (Exception e) { ErrorDialogue errorDialogue = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiVideoController) { try { this.Architecture = DataRetriever.ConvertVideoArchitecture(DataRetriever.GetValueUInt16(wmiVideoController, "VideoArchitecture")); this.Availability = DataRetriever.ConvertAvailability(DataRetriever.GetValueUInt16(wmiVideoController, "Availability")); this.BitsPerPixel = DataRetriever.GetValueUInt32(wmiVideoController, "CurrentBitsPerPixel"); this.CurrentRefresh = DataRetriever.GetValueUInt32(wmiVideoController, "CurrentRefreshRate"); this.DriverDate = DataRetriever.GetValueDateString(wmiVideoController, "DriverDate"); this.DriverVersion = DataRetriever.GetValue(wmiVideoController, "DriverVersion"); this.ErrorDescription = DataRetriever.GetValue(wmiVideoController, "ErrorDescription"); this.HorizontalResolution = DataRetriever.GetValueUInt32(wmiVideoController, "CurrentHorizontalResolution"); this.MaxRefresh = DataRetriever.GetValueUInt32(wmiVideoController, "MaxRefreshRate"); this.MemorySize = DataRetriever.GetValueUInt32(wmiVideoController, "AdapterRAM"); this.MemorySize = this.MemorySize / (1024 * 1024); this.MemoryType = DataRetriever.ConvertVideoArchitecture(DataRetriever.GetValueUInt16(wmiVideoController, "VideoMemoryType")); this.MinRefresh = DataRetriever.GetValueUInt32(wmiVideoController, "MinRefreshRate"); this.Name = DataRetriever.GetValue(wmiVideoController, "Name"); this.Status = DataRetriever.GetValue(wmiVideoController, "Status"); this.VerticalResolution = DataRetriever.GetValueUInt32(wmiVideoController, "CurrentVerticalResolution"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiUSBEntity) { try { this.Availability = DataRetriever.GetValue(wmiUSBEntity, "Availability"); this.Description = DataRetriever.GetValue(wmiUSBEntity, "Description"); this.ErrorDescription = DataRetriever.GetValue(wmiUSBEntity, "ErrorDescription"); this.Manufacturer = DataRetriever.GetValue(wmiUSBEntity, "Manufacturer"); this.Name = DataRetriever.GetValue(wmiUSBEntity, "Name"); this.Status = DataRetriever.GetValue(wmiUSBEntity, "Status"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
// The main information handler for the classes. // This splits out the data in the ManagementObject into the class's own properties public void GetInfo(ManagementObject wmiProcessor) { // If anything fails, the try loop will just end without making a fuss // Because of the default values, N/A will be displayed everywhere if something fails here. try { // Architecture, Availability and several other properties are given as numerical codes. // A dictionary with the codes is used to convert these to strings. this.Architecture = DataRetriever.ConvertArchitecture(DataRetriever.GetValueUInt16(wmiProcessor, "Architecture")); this.Availability = DataRetriever.ConvertAvailability(DataRetriever.GetValueUInt16(wmiProcessor, "Availability")); this.CacheL2 = DataRetriever.GetValueUInt32(wmiProcessor, "L2CacheSize"); this.CacheL3 = DataRetriever.GetValueUInt32(wmiProcessor, "L3CacheSize"); this.Caption = DataRetriever.GetValue(wmiProcessor, "Caption"); this.Cores = DataRetriever.GetValueUInt32(wmiProcessor, "NumberOfCores"); this.CurrentClock = DataRetriever.GetValueUInt32(wmiProcessor, "CurrentClockSpeed"); this.ErrorDescription = DataRetriever.GetValue(wmiProcessor, "ErrorDescription"); this.Family = DataRetriever.ConvertFamily(DataRetriever.GetValueUInt16(wmiProcessor, "Family")); this.Manufacturer = DataRetriever.GetValue(wmiProcessor, "Manufacturer"); this.Model = DataRetriever.GetValue(wmiProcessor, "Name"); this.ReferenceClock = DataRetriever.GetValueUInt32(wmiProcessor, "MaxClockSpeed"); this.Revision = DataRetriever.GetValueUInt16(wmiProcessor, "Revision"); this.Socket = DataRetriever.GetValue(wmiProcessor, "SocketDesignation"); this.Status = DataRetriever.GetValue(wmiProcessor, "Status"); this.Stepping = DataRetriever.GetValue(wmiProcessor, "Stepping"); //this.ThermalDesignPower = DataRetriever.GetValueFloat(wmiProcessor, "CurrentVoltage"); this.Threads = DataRetriever.GetValueUInt32(wmiProcessor, "NumberOfLogicalProcessors"); this.GetVolatileInfo(); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiSystemSlot, ManagementObject wmiPNPEntity) { try { this.Manufacturer = DataRetriever.GetValue(wmiSystemSlot, "Manufacturer"); this.Model = DataRetriever.GetValue(wmiSystemSlot, "Name"); this.Slot = DataRetriever.GetValue(wmiSystemSlot, "SlotDesignation"); this.Status = DataRetriever.GetValue(wmiSystemSlot, "Status"); this.Tag = DataRetriever.GetValue(wmiSystemSlot, "Tag"); // Voltage conversion UInt16[] voltages = DataRetriever.GetValueUInt16Array(wmiSystemSlot, "VccMixedVoltageSupport"); string[] voltageStrings = new string[voltages.Length]; for (int i = 0; i < voltages.Length - 1; i++) { voltageStrings[i] = DataRetriever.ConvertVoltage(Convert.ToUInt16(voltages[i])); } this.VccVoltageModes = String.Join(", ", voltageStrings); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiCDROMDrive) { try { this.Availability = DataRetriever.ConvertAvailability(DataRetriever.GetValueUInt16(wmiCDROMDrive, "Availability")); this.ErrorDescription = DataRetriever.GetValue(wmiCDROMDrive, "ErrorDescription"); this.Manufacturer = DataRetriever.GetValue(wmiCDROMDrive, "Manufacturer"); this.MediaType = DataRetriever.GetValue(wmiCDROMDrive, "MediaType"); this.Name = DataRetriever.GetValue(wmiCDROMDrive, "Name"); this.Status = DataRetriever.GetValue(wmiCDROMDrive, "Status"); this.TransferRate = DataRetriever.GetValueFloat(wmiCDROMDrive, "TransferRate"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public static UInt16[] GetValueUInt16Array(ManagementObject managementObject, string field) { try { return (UInt16[])managementObject[field]; } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); errorReporter.ShowDialog(); return null; } }
public static ManagementObject[] GetWMIData(string wmiClass, string whereClause, string scope) { try { // If a where clause has been set, prepare the clause to add to the query string if (whereClause != "") { whereClause = " WHERE " + whereClause; } // Create a search query string query = "SELECT * FROM " + wmiClass + whereClause; ManagementObjectSearcher wmiSearcher = new ManagementObjectSearcher("root\\" + scope, query); ManagementObjectCollection matches = wmiSearcher.Get(); // Create an array to hold the matches ManagementObject[] matchArray = new ManagementObject[matches.Count]; // If matches found, copy to output if (matches.Count > 0) { // Copy the search matches into this array matches.CopyTo(matchArray, 0); } else { // Return a single, null element if nothing is found matchArray = new ManagementObject[1] { null }; } // Return array return matchArray; } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); return null; } }
public void GetSoftwareInfo() { // Complete error catching for information gathering try { if (abortRetrieval) return; Splash.AddProgressInfo("Processing Driver Information...", 6); GetDrivers(); if (abortRetrieval) return; Splash.AddProgressInfo("Processing Running Processes...", 5); GetProcesses(); if (abortRetrieval) return; Splash.AddProgressInfo("Processing Windows Logs...", 10); GetLogs(); if (abortRetrieval) return; Splash.AddProgressInfo("Processing Software Information...", 15); GetSoftware(); if (abortRetrieval) return; Splash.AddProgressInfo("Processing Address Maps...", 18); GetAddresses(); if (abortRetrieval) return; Splash.AddProgressInfo("Processing IRQ Maps...", 14); GetIRQs(); if (abortRetrieval) return; Splash.AddProgressInfo("Processing Conflicts...", 3); GetConflicts(); } catch (Exception e) { ErrorDialogue errorDialogue = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiPhysicalMemory) { try { //this.Availability = DataRetriever.ConvertAvailability(DataRetriever.GetValueUInt16(wmiPhysicalMemory, "Availability")); this.Bank = DataRetriever.GetValue(wmiPhysicalMemory, "BankLabel"); this.Capacity = DataRetriever.GetValueUInt64(wmiPhysicalMemory, "Capacity"); // Convert to MB this.Capacity = this.Capacity / (1024 * 1024); this.DeviceLocation = DataRetriever.GetValue(wmiPhysicalMemory, "DeviceLocator"); //this.ErrorDescription = DataRetriever.GetValue(wmiPhysicalMemory, "ErrorDescription"); this.Manufacturer = DataRetriever.GetValue(wmiPhysicalMemory, "Manufacturer"); this.Model = DataRetriever.GetValue(wmiPhysicalMemory, "Name"); this.Speed = DataRetriever.GetValueUInt32(wmiPhysicalMemory, "Speed"); this.Status = DataRetriever.GetValue(wmiPhysicalMemory, "Status"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
/// <summary> /// Deletes an entire computer from the database. /// </summary> /// <param name="id">The ID of the computer to delete.</param> /// <returns>True if the operation was successful, otherwise false.</returns> public static bool DeleteFromDB(int id) { if (Connection != null && !abortOperation) { try { Connection.Open(); // If the database has been opened, continue if (Connection.State == ConnectionState.Open) { SQLiteCommand command = Connection.CreateCommand(); // Deletes a computer from the all tables in the database prior to updating the information foreach (string classString in ClassList.DatabaseClasses) { if (abortOperation) break; command.CommandText = "DELETE FROM " + classString + " WHERE id='" + id + "'"; command.ExecuteNonQuery(); } // Delete from comments command.CommandText = "DELETE FROM comments WHERE id='" + id + "'"; command.ExecuteNonQuery(); // End Connection.Close(); return true; } else { Connection.Close(); return false; } } catch (Exception e) { Connection.Close(); ErrorDialogue errorReporter = new ErrorDialogue(e); return false; } } else { return false; } }
public void GetInfo(ManagementObject wmiPnPSignedDriver) { try { this.Date = DataRetriever.GetValueDateString(wmiPnPSignedDriver, "DriverDate"); // Try a Friendly Name first // If not, do a normal name, then DeviceName, then give up this.Name = DataRetriever.GetValue(wmiPnPSignedDriver, "FriendlyName"); if (this.Name == "") this.Name = DataRetriever.GetValue(wmiPnPSignedDriver, "DriverName"); if (this.Name == "") this.Name = DataRetriever.GetValue(wmiPnPSignedDriver, "DeviceName"); if (this.Name == "") this.Name = "Unknown"; this.Publisher = DataRetriever.GetValue(wmiPnPSignedDriver, "DriverProviderName"); this.Version = DataRetriever.GetValue(wmiPnPSignedDriver, "DriverVersion"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
/// <summary> /// Gets all of the ID numbers present in the database. /// </summary> /// <returns>An array of ID numbers.</returns> public static int[] GetIDNumbers() { // Gets the ID numbers of all known computers if (Connection != null && !abortOperation) { try { List<int> idNumbers = new List<int>(); SQLiteCommand command = Connection.CreateCommand(); SQLiteDataReader data; // Get all IDs from one of the tables. Comments is best as IDs are unique to the rows. Connection.Open(); command.CommandText = "SELECT id FROM comments"; data = command.ExecuteReader(); // For each record while (data.Read()) { // Add the id field to the id numbers list idNumbers.Add(Convert.ToInt32(data[0])); } Connection.Close(); // Set the list of ids as an array of integers return idNumbers.ToArray(); } catch (Exception e) { Connection.Close(); ErrorDialogue errorReporter = new ErrorDialogue(e); return null; } } else { return null; } }
public void GetInfo(EventLogEntry eventLog) { try { this.Category = eventLog.Category; this.DateTime = eventLog.TimeGenerated.ToShortDateString() + " " + eventLog.TimeGenerated.ToLongTimeString(); this.EventID = eventLog.InstanceId; this.Level = eventLog.EntryType.ToString(); this.Message = eventLog.Message; this.Source = eventLog.Source; } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetInfo(ManagementObject wmiATAPISmartData) { try { // Convert the Vendor Specific bytes into SMART Data byte[] vendorSpecific = DataRetriever.GetValueBytes(wmiATAPISmartData, "VendorSpecific"); SMARTData data = new SMARTData(vendorSpecific); Int32 attributeData = 0; // Because the field names above are the same as those given by the SMARTData class, // we can loop through all the attributes in the SMART Data variable and add the data to // the class's fields using System Reflection methods. foreach (SMARTAttribute attribute in data.Attributes) { // Convert vendor data byte array to integer attributeData = 0; for (int i = 0; i < 5; i++) { // For each of the 6 bytes (not including the last two for flags), add the byte data multiplied by its offset attributeData += Convert.ToInt32(attribute.VendorData[i]) * (i * 256); } this.GetType().GetField(Convert.ToString(attribute.AttributeType)).SetValue(this, Convert.ToUInt16(attribute.Value)); } } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
public void GetVoltatileInfo() { try { ManagementObject[] perfData = DataRetriever.GetWMIData("Win32_PerfFormattedData_PerfProc_Process", "IDProcess=" + this.PID); this.CPU = DataRetriever.GetValueUInt16(perfData[0], "PercentProcessorTime"); this.IO = DataRetriever.GetValueUInt64(perfData[0], "IODataBytesPerSec"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }
/// <summary> /// Adds a single device instance to the database. /// </summary> /// <param name="deviceInstance">The object to store into the database.</param> /// <param name="className">The name of the class the object belongs to.</param> /// <param name="id">The numerical ID of the computer of which the object belongs.</param> /// <param name="instance">The numerical ID of the object in its parent class.</param> /// <returns>True if the operation was successful, otherwise false.</returns> public static bool AddToDB(object deviceInstance, string className, int id, int instance) { if (deviceInstance != null && Connection != null && !abortOperation) { try { Connection.Open(); // If the database has been opened, continue if (Connection.State == ConnectionState.Open) { // Get the properties of the given device class FieldInfo[] classFields = deviceInstance.GetType().GetFields(); SQLiteCommand command = Connection.CreateCommand(); // Create a SQL statement to add values command.CommandText = "INSERT INTO " + className + " VALUES('" + id + "','" + instance; // Loop through each field in the class to get values foreach (FieldInfo field in classFields) { // If it's SMARTData, don't store it! if (field.FieldType != typeof(SMARTData)) { command.CommandText += "','" + field.GetValue(deviceInstance); } } // End the query string and execute it command.CommandText += "')"; command.ExecuteNonQuery(); // End Connection.Close(); return true; } else { Connection.Close(); return false; } } catch (Exception e) { Connection.Close(); ErrorDialogue errorReporter = new ErrorDialogue(e); return false; } } else { return false; } }
/// <summary> /// Prepares the database for first use. Will write a database to disk if none exists. /// </summary> /// <returns>True if initialisation succeeded, otherwise false.</returns> public static bool Initialise() { try { if (File.Exists("Heuristics.db")) { // Create a new connection to the existing file Connection = new SQLiteConnection("Data Source=Heuristics.db;New=False;Compress=True;"); // Test an open/close command Connection.Open(); Connection.Close(); } else { // Create a new database Connection = new SQLiteConnection("Data Source=Heuristics.db;New=True;Compress=True;"); Connection.Open(); // Create tables SQLiteCommand command = Connection.CreateCommand(); command.CommandText = "CREATE TABLE comments(" + "id INTEGER NOT NULL PRIMARY KEY," + "comments TEXT)"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE processor(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Architecture TEXT," + "Availability TEXT," + "CacheL2 INTEGER," + "CacheL3 INTEGER," + "Caption TEXT," + "Cores INTEGER," + "CurrentClock INTEGER," + "ErrorDescription TEXT," + "Family TEXT," + "Manufacturer TEXT," + "Model TEXT," + "ReferenceClock INTEGER," + "Revision INTEGER," + "Socket TEXT," + "Status TEXT," + "Stepping TEXT," + "Temperature INT," + "ThermalDesignPower INTEGER," + "Threads INTEGER," + "Usage INTEGER," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE motherboard(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Availability TEXT," + "ErrorDescription TEXT," + "Manufacturer TEXT," + "Model TEXT," + "ProductID TEXT," + "SerialID TEXT," + "Status TEXT," + "Temperature INTEGER," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE bios(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Info TEXT," + "SerialID TEXT," + "Version TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE memorydevice(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Availability TEXT," + "Bank TEXT," + "Capacity INTEGER," + "DeviceLocation TEXT," + "ErrorDescription TEXT," + "Manufacturer TEXT," + "Model TEXT," + "Speed INTEGER," + "Status TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE graphicsadapter(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Architecture TEXT," + "Availability TEXT," + "BitsPerPixel INTEGER," + "CurrentClock INTEGER," + "CurrentRefresh INTEGER," + "DriverDate TEXT," + "DriverVersion TEXT," + "ErrorDescription TEXT," + "HorizontalResolution INTEGER," + "MaxRefresh INTEGER," + "MemorySize INTEGER," + "MemoryType TEXT," + "MinRefresh INTEGER," + "Name TEXT," + "Status TEXT," + "Temperature INTEGER," + "VerticalResolution INTEGER," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE networkadapter(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "AdapterType TEXT," + "Availability TEXT," + "ConnectionStatus TEXT," + "CurrentSpeed INTEGER," + "ErrorDescription TEXT," + "Manufacturer TEXT," + "MACAddress TEXT," + "MaxSpeed INTEGER," + "Name TEXT," + "PhysicalAdapter INTEGER," + "Status TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE harddrive(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Availability TEXT," + "Capacity INTEGER," + "ErrorDescription TEXT," + "Manufacturer TEXT," + "Name TEXT," + "Partitions INTEGER," + "Status TEXT," + "Temperature INTEGER," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE opticaldrive(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Availability TEXT," + "ErrorDescription TEXT," + "Manufacturer TEXT," + "Media Type TEXT," + "Name TEXT," + "Status TEXT," + "TransferRate INTEGER," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE pcicard(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Manufacturer TEXT," + "Model TEXT," + "Slot TEXT," + "Status TEXT," + "Tag TEXT," + "VccVoltageModes TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE usbdevice(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Availability TEXT," + "Description TEXT," + "ErrorDescription TEXT," + "Manufacturer TEXT," + "Name TEXT," + "Status TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE driver(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Date TEXT," + "Name TEXT," + "Publisher TEXT," + "Version TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE software(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Date TEXT," + "Name TEXT," + "Publisher TEXT," + "Version TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE conflict(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Device1 TEXT," + "Device2 TEXT," + "Resource TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE process(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "CPU INTEGER," + "ExecutableName TEXT," + "ImageName TEXT," + "IO INTEGER," + "Memory INTEGER," + "PID INTEGER," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE log(" + "id INTEGER NOT NULL," + "instance INTEGER NOT NULL," + "Category TEXT," + "DateTime TEXT," + "EventID INTEGER," + "Level TEXT," + "Message TEXT," + "Source TEXT," + "FOREIGN KEY(id) REFERENCES computer(id)," + "PRIMARY KEY(id, instance))"; command.ExecuteNonQuery(); Connection.Close(); } return true; } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); return false; } }
// This class requires 2 WMI classes for all data public void GetInfo(ManagementObject wmiBaseboard, ManagementObject wmiMotherboardDevice) { try { this.Availability = DataRetriever.ConvertAvailability(DataRetriever.GetValueUInt16(wmiMotherboardDevice, "Availability")); this.ErrorDescription = DataRetriever.GetValue(wmiMotherboardDevice, "ErrorDescription"); this.Manufacturer = DataRetriever.GetValue(wmiBaseboard, "Manufacturer"); this.Model = DataRetriever.GetValue(wmiBaseboard, "Model"); this.ProductID = DataRetriever.GetValue(wmiBaseboard, "Product"); this.SerialID = DataRetriever.GetValue(wmiBaseboard, "SerialNumber"); this.Status = DataRetriever.GetValue(wmiBaseboard, "Status"); } catch (Exception e) { ErrorDialogue errorReporter = new ErrorDialogue(e); } }