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 current installed memory banks on the machine. /// </summary> public static List <RamInfo> GetMemory() { List <RamInfo> memoryModules = null; ManagementObjectSearcher memoryQuery = new ManagementObjectSearcher( @"SELECT MemoryType, Capacity, Speed FROM Win32_PhysicalMemory " ); try { ManagementObjectCollection memoryInfo = memoryQuery.Get(); memoryModules = new List <RamInfo>(); foreach (var item in memoryInfo) { RamInfo ram = new RamInfo(); ram.MemoryType = RamInfo.ObtainType((UInt32.Parse(item["MemoryType"].ToString()))); ram.Capacity = (int)(UInt64.Parse(item["Capacity"].ToString()) / 1073741824); ram.Speed = Int32.Parse(item["Speed"].ToString()); memoryModules.Add(ram); } } catch (Exception exc) { Logger.Error("GetMemory() error...", exc); memoryModules = null; } return(memoryModules); }
/// <summary> /// Gets a list of the current installed memory banks on the machine. /// </summary> public static List<RamInfo> GetMemory() { List<RamInfo> memoryModules = null; ManagementObjectSearcher memoryQuery = new ManagementObjectSearcher( @"SELECT MemoryType, Capacity, Speed FROM Win32_PhysicalMemory " ); try { ManagementObjectCollection memoryInfo = memoryQuery.Get(); memoryModules = new List<RamInfo>(); foreach (var item in memoryInfo) { RamInfo ram = new RamInfo(); ram.MemoryType = RamInfo.ObtainType((UInt32.Parse(item["MemoryType"].ToString()))); ram.Capacity = (int)(UInt64.Parse(item["Capacity"].ToString()) / 1073741824); ram.Speed = Int32.Parse(item["Speed"].ToString()); memoryModules.Add(ram); } } catch (Exception exc) { Logger.Error("GetMemory() error...", exc); memoryModules = null; } return memoryModules; }
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()); }