private void GetData() { dataCollector = new DataCollector(connectionHandler); cpus = dataCollector.GetCPUData(); disks = dataCollector.GetDiskData(); nics = dataCollector.GetNICData(); pageFiles = dataCollector.GetPageFileData(); physicalDisks = dataCollector.GetPhysicalDiskData(); features = dataCollector.GetFeatureData(); systemInfo = dataCollector.GetSystemInfo(); }
public DataClasses.SystemInfo GetSystemInfo() { DataClasses.SystemInfo systeminfo = new DataClasses.SystemInfo(); // Run queries for the four relevant WMI classes ManagementObject computerSystem = (connection.RunQuery("SELECT Name, SystemType, ChassisSKUNumber, Manufacturer, Model, Domain, TotalPhysicalMemory FROM Win32_ComputerSystem"))[0]; ManagementObject operatingSystem = (connection.RunQuery("SELECT Caption, CSName, LastBootUpTime, InstallDate, BuildNumber, Version, " + "CurrentTimeZone, OSLanguage, BootDevice, SystemDirectory, TotalVirtualMemorySize FROM Win32_OperatingSystem"))[0]; ManagementObject bios = (connection.RunQuery("SELECT Version, SerialNumber FROM Win32_Bios"))[0]; ManagementObject perfOSMem = (connection.RunQuery("SELECT AvailableMBytes, CommittedBytes, CommitLimit FROM Win32_PerfFormattedData_PerfOS_Memory"))[0]; ManagementObject timeZone = (connection.RunQuery("SELECT StandardName FROM win32_Timezone"))[0]; // Format data and assign to return object systeminfo.AvailableMemory = perfOSMem.GetPropertyValue("AvailableMBytes")?.ToString() ?? "" + "MB"; systeminfo.BiosVersion = bios.GetPropertyValue("Version")?.ToString() ?? ""; systeminfo.BootDevice = operatingSystem.GetPropertyValue("BootDevice")?.ToString() ?? ""; string boot = operatingSystem.GetPropertyValue("LastBootUpTime")?.ToString() ?? ""; if (boot != null) { systeminfo.BootTime = ManagementDateTimeConverter.ToDateTime(boot).ToString("MM/dd/yyyy hh:mm:ss tt"); } systeminfo.ChassisType = computerSystem.GetPropertyValue("ChassisSKUNumber")?.ToString() ?? ""; systeminfo.CommitLimit = ((UInt64)(perfOSMem.GetPropertyValue("CommitLimit")) / 1048576).ToString() + "MB"; systeminfo.Committed = ((UInt64)(perfOSMem.GetPropertyValue("CommittedBytes")) / 1048576).ToString() + "MB"; systeminfo.Domain = computerSystem.GetPropertyValue("Domain")?.ToString() ?? ""; systeminfo.InUseMemory = (((UInt64)(computerSystem.GetPropertyValue("TotalPhysicalMemory")) - (UInt64)(perfOSMem.GetPropertyValue("AvailableMBytes"))) / 1048576).ToString() + "MB"; string install = operatingSystem.GetPropertyValue("InstallDate")?.ToString() ?? ""; if (install != null) { systeminfo.InstallDate = ManagementDateTimeConverter.ToDateTime(install).ToString("MM/dd/yyyy hh:mm:ss tt"); } systeminfo.Language = operatingSystem.GetPropertyValue("OSLanguage")?.ToString() ?? ""; systeminfo.Manufacturer = computerSystem.GetPropertyValue("Manufacturer")?.ToString() ?? ""; systeminfo.Model = computerSystem.GetPropertyValue("Model")?.ToString() ?? ""; systeminfo.OS = operatingSystem.GetPropertyValue("Caption")?.ToString() ?? ""; systeminfo.OSBuild = operatingSystem.GetPropertyValue("BuildNumber")?.ToString() ?? ""; systeminfo.OSVersion = operatingSystem.GetPropertyValue("Version")?.ToString() ?? ""; systeminfo.SerialNumber = bios.GetPropertyValue("SerialNumber")?.ToString() ?? ""; systeminfo.SysName = operatingSystem.GetPropertyValue("CSName")?.ToString() ?? ""; systeminfo.SystemDir = operatingSystem.GetPropertyValue("SystemDirectory")?.ToString() ?? ""; systeminfo.SystemType = computerSystem.GetPropertyValue("SystemType")?.ToString() ?? ""; systeminfo.TimeZone = timeZone.GetPropertyValue("StandardName")?.ToString() ?? ""; systeminfo.TotalPhysicalMemory = ((UInt64)(computerSystem.GetPropertyValue("TotalPhysicalMemory")) / 1048576).ToString() + "MB"; systeminfo.TotalVirtualMemory = ((UInt64)(operatingSystem.GetPropertyValue("TotalVirtualMemorySize")) / 1048576).ToString() + "MB"; return(systeminfo); }