public void getComponent(string hwclass, string syntax) { ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM " + hwclass); foreach (ManagementObject mj in mos.Get()) { SystemInfo.AppendText(Convert.ToString(mj[syntax]) + "\n"); } }
private void getRAMsize() { ManagementClass mc = new ManagementClass("Win32_ComputerSystem"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject item in moc) { SystemInfo.AppendText(Convert.ToString(Math.Round(Convert.ToDouble(item.Properties["TotalPhysicalMemory"].Value) / (1048576 * 1024), 0)) + " GB\n"); } }
private void gatherSystemInfo() { SystemInfo.AppendText("Operating System: "); SystemInfo.AppendText(System.Runtime.InteropServices.RuntimeInformation.OSDescription); SystemInfo.AppendText(Environment.Is64BitOperatingSystem ? " 64-bit" : " 32-bit"); SystemInfo.AppendText("\nCPU: "); getComponent("Win32_Processor", "Name"); SystemInfo.AppendText("RAM: "); getRAMsize(); SystemInfo.AppendText("GPU(s): "); getComponent("Win32_VideoController", "Name"); SystemInfo.AppendText("Disk(s) information: "); DiskChecker(); }
private void DiskChecker() { ManagementScope scope = new ManagementScope(@"\\.\root\microsoft\windows\storage"); ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM MSFT_PhysicalDisk"); scope.Connect(); searcher.Scope = scope; ArrayList drives = new ArrayList(); foreach (ManagementObject queryObj in searcher.Get()) { switch (Convert.ToInt16(queryObj["MediaType"])) { case 1: drives.Add("Unspecified"); break; case 3: drives.Add("HDD"); break; case 4: drives.Add("SSD"); break; case 5: drives.Add("SCM"); break; default: drives.Add("Unspecified"); break; } } searcher.Dispose(); DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { int i = 0; SystemInfo.AppendText("\nDrive " + d.Name); SystemInfo.AppendText("\nDrive type: " + d.DriveType + " " + drives[i]); if (d.IsReady == true) { SystemInfo.AppendText("\nVolume label: " + d.VolumeLabel); SystemInfo.AppendText("\nFile system: " + d.DriveFormat); SystemInfo.AppendText("\nAvailable space to current user: "******" GB"); SystemInfo.AppendText("\nTotal available space: " + (d.TotalFreeSpace / (1048576 * 1024), 0) + " GB"); SystemInfo.AppendText("\nTotal size of drive: " + (d.TotalSize / (1048576 * 1024), 0) + " GB"); } i++; } if (drives[0].Equals("SSD")) { ProgressInfo.AppendText("\nLooks like your system is based on a SSD. We strongly recommend you to use recommended settings for SSD based systems."); ProgressInfo.AppendText("\nRecommended settings for SSD based systems selected."); Recommended.SelectedIndex = 1; } else { ProgressInfo.AppendText("\nLooks like your system is based on non-SSD. We strongly recommend you to use recommended settings for non-SSD based systems."); ProgressInfo.AppendText("\nRecommended settings for non-SSD based systems selected."); Recommended.SelectedIndex = 0; } }