private void PopulateHardwareInfo() { Configuration = SystemUtils.GetComputerConfiguration(); OperatingSystemInfo operatingSystem = Configuration.OperatingSystem; List <CpuInfo> processors = Configuration.Processors; List <RamInfo> memory = Configuration.MemoryModules; List <StorageDeviceInfo> storage = Configuration.StorageDevices; // OS txtBoxOsName.Text = operatingSystem.Name; txtBoxOsType.Text = operatingSystem.Is64bit ? "64 bit" : "32 bit"; // CPU CpuInfo cpu = processors.First(); txtBoxCpuName.Text = cpu.Name; txtBoxCpuFrequency.Text = String.Format("{0} MHz", cpu.MaxClockSpeed); txtBoxCpuThreads.Text = cpu.Threads.ToString(); txtBoxCpuCount.Text = processors.Count.ToString(); // RAM RamInfo ram = memory.First(); int capacity = 0; foreach (var bank in memory) { capacity += bank.Capacity; } txtBoxMemoryCapacity.Text = String.Format("{0} GB", capacity); txtBoxMemoryType.Text = ram.MemoryType.ToString(); txtBoxMemoryFrequency.Text = String.Format("{0} MHz", ram.Speed); txtBoxMemoryBanks.Text = memory.Count.ToString(); // STORAGE string benchmarkDataDirectoryRoot = Path.GetPathRoot(BenchmarkTests.First().Database.DataDirectory); StorageDeviceInfo dataDrive = storage.Find(drive => drive.DriveLetters.Contains(benchmarkDataDirectoryRoot.Trim('\\'))); comboBoxStorageModel.Items.AddRange(storage.Select(device => device.Model).ToArray()); int selectedIndex = comboBoxStorageModel.Items.IndexOf(dataDrive.Model); comboBoxStorageModel.SelectedIndex = selectedIndex; txtBoxHddSize.Text = String.Format("{0} GB", dataDrive.Size); }
/// <summary> /// Gets a list of the storage devices installed on the machine. /// </summary> public static List <StorageDeviceInfo> GetStorageDevices() { List <StorageDeviceInfo> storages = null; try { ManagementClass wmiClass = new ManagementClass(@"Win32_DiskDrive"); ManagementObjectCollection storageDrives = wmiClass.GetInstances(); storages = new List <StorageDeviceInfo>(); foreach (ManagementObject disk in storageDrives) { if (Int32.Parse(disk["Partitions"].ToString()) == 0) // Not a hard drive. { continue; } StorageDeviceInfo storage = new StorageDeviceInfo(); storage.Model = disk["Model"].ToString(); storage.Size = (UInt64.Parse(disk["Size"].ToString()) / 1073741824); storage.DriveLetters = new List <string>(); foreach (ManagementObject diskPartition in disk.GetRelated("Win32_DiskPartition")) { foreach (ManagementBaseObject logicalPartition in diskPartition.GetRelated("Win32_LogicalDisk")) { storage.DriveLetters.Add(logicalPartition["Name"].ToString()); } } storages.Add(storage); } } catch (Exception exc) { Logger.Error("GetStorageDevices() error...", exc); storages = null; } return(storages); }
public static void ExportComputerConfiguration(StreamWriter writer, ComputerConfiguration computerInfo) { StringBuilder builder = new StringBuilder(); builder.AppendLine("Computer specification:"); builder.AppendLine("Operating system:;;;Processors:;;;;Memory modules:;;;;Storages:"); builder.AppendLine("Name;Is64Bit;;Name;Threads;Max clock speed (MHz);;Type;Capacity (GB);Speed (MHz);;Model;Size (GB);Partitions;"); builder.Append(computerInfo.OperatingSystem.Name + ";"); builder.Append(computerInfo.OperatingSystem.Is64bit + ";;"); CpuInfo firstProcessor = computerInfo.Processors.First(); builder.Append(firstProcessor.Name + ";"); builder.Append(firstProcessor.Threads + ";"); builder.Append(firstProcessor.MaxClockSpeed + ";;"); RamInfo firstRam = computerInfo.MemoryModules.First(); builder.Append(firstRam.MemoryType + ";"); builder.Append(firstRam.Capacity + ";"); builder.Append(firstRam.Speed + ";;"); StorageDeviceInfo firstStorage = computerInfo.StorageDevices.First(); builder.Append(firstStorage.Model + ";"); builder.Append(firstStorage.Size + ";"); firstStorage.DriveLetters.ForEach(x => builder.Append(x.Replace(":", ""))); builder.Append(Environment.NewLine); int count = Math.Max(Math.Max(computerInfo.Processors.Count, computerInfo.MemoryModules.Count), computerInfo.StorageDevices.Count); for (int i = 1; i < count; i++) { builder.Append(";;;"); if (computerInfo.Processors.Count <= i) { builder.Append(";;;;"); } else { CpuInfo info = computerInfo.Processors[i]; builder.Append(info.Name + ";"); builder.Append(info.Threads + ";"); builder.Append(info.MaxClockSpeed + ";;"); } if (computerInfo.MemoryModules.Count <= i) { builder.Append(";;;;"); } else { RamInfo info = computerInfo.MemoryModules[i]; builder.Append(firstRam.MemoryType + ";"); builder.Append(firstRam.Capacity + ";"); builder.Append(firstRam.Speed + ";;"); } if (computerInfo.StorageDevices.Count <= i) { builder.Append(";;;;"); } else { StorageDeviceInfo info = computerInfo.StorageDevices[i]; builder.Append(info.Model + ";"); builder.Append(info.Size + ";"); info.DriveLetters.ForEach(x => builder.Append(x)); } } writer.WriteLine(builder.ToString()); }
/// <summary> /// Gets a list of the storage devices installed on the machine. /// </summary> public static List<StorageDeviceInfo> GetStorageDevices() { List<StorageDeviceInfo> storages = null; try { ManagementClass wmiClass = new ManagementClass(@"Win32_DiskDrive"); ManagementObjectCollection storageDrives = wmiClass.GetInstances(); storages = new List<StorageDeviceInfo>(); foreach (ManagementObject disk in storageDrives) { if (Int32.Parse(disk["Partitions"].ToString()) == 0) // Not a hard drive. continue; StorageDeviceInfo storage = new StorageDeviceInfo(); storage.Model = disk["Model"].ToString(); storage.Size = (UInt64.Parse(disk["Size"].ToString()) / 1073741824); storage.DriveLetters = new List<string>(); foreach (ManagementObject diskPartition in disk.GetRelated("Win32_DiskPartition")) { foreach (ManagementBaseObject logicalPartition in diskPartition.GetRelated("Win32_LogicalDisk")) { storage.DriveLetters.Add(logicalPartition["Name"].ToString()); } } storages.Add(storage); } } catch (Exception exc) { Logger.Error("GetStorageDevices() error...", exc); storages = null; } return storages; }