private void Form1_Load(object sender, EventArgs e) { DiskDriveInfo Test = new DiskDriveInfo(); VideoControllerInfo Test3 = new VideoControllerInfo(); Test.GetInfo(); Test3.GetInfo(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm form = new MainForm(); try { ProcessorInfo processorInfo = new ProcessorInfo(); PhysicalMemoryInfo physicalMemoryInfo = new PhysicalMemoryInfo(); DiskDriveInfo diskDriveInfo = new DiskDriveInfo(); MainFormPresenter presenter = new MainFormPresenter(form, processorInfo, physicalMemoryInfo, diskDriveInfo); Application.Run(form); } catch (Exception ex) { MessageBox.Show(ex.Message, "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }
public SystemInfo() { var osQuery = new WqlObjectQuery("SELECT * FROM Win32_OperatingSystem"); var osSearcher = new ManagementObjectSearcher(osQuery); foreach (var os in osSearcher.Get()) { memory.TotalPhysicalMemory = Convert.ToUInt64(os["TotalVisibleMemorySize"]) / 1024 / 1024; memory.AvailablePhysicalMemory = Convert.ToUInt64(os["FreePhysicalMemory"]) / 1024 / 1024; memory.TotalVirtualMemory = Convert.ToUInt64(os["TotalVirtualMemorySize"]) / 1024 / 1024; memory.AvailableVirtualMemory = Convert.ToUInt64(os["FreeVirtualMemory"]) / 1024 / 1024; } //处理器 ManagementClass cimobjectProcessor = new ManagementClass("Win32_Processor"); ManagementObjectCollection mocProcessor = cimobjectProcessor.GetInstances(); foreach (ManagementObject mo in mocProcessor) { if (mo["ProcessorId"] != null) processor.SerialNumber = mo.Properties["ProcessorId"].Value.ToString().Trim(); if (mo["Name"] != null) processor.Name = mo.Properties["Name"].Value.ToString().Trim(); if (mo["Manufacturer"] != null) processor.Manufacturer = mo.Properties["Manufacturer"].Value.ToString().Trim(); } //操作系统 ManagementClass cimobjectOperatingSystem = new ManagementClass("Win32_OperatingSystem"); ManagementObjectCollection mocOperatingSystem = cimobjectOperatingSystem.GetInstances(); if (System.Environment.Is64BitOperatingSystem) operatingSystem.OSLevel = "64"; foreach (ManagementObject mo in mocOperatingSystem) { if (mo["SerialNumber"] != null) operatingSystem.SerialNumber = mo.Properties["SerialNumber"].Value.ToString().Trim(); if (mo["Caption"] != null) operatingSystem.Caption = mo.Properties["Caption"].Value.ToString().Trim(); if (mo["InstallDate"] != null) operatingSystem.InstallDate = mo.Properties["InstallDate"].Value.ToString().Trim(); if (mo["LastBootUpTime"] != null) operatingSystem.LastBootUpTime = mo.Properties["LastBootUpTime"].Value.ToString().Trim(); if (mo["LocalDateTime"] != null) operatingSystem.LocalDateTime = mo.Properties["LocalDateTime"].Value.ToString().Trim(); } //获取硬盘 ManagementClass cimobjectDiskDrive = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection mocDiskDrive = cimobjectDiskDrive.GetInstances(); diskDrivelist = new List<DiskDriveInfo>(); foreach (ManagementObject mo in mocDiskDrive) { DiskDriveInfo diskDrive = new DiskDriveInfo(); if (mo["Caption"] != null) diskDrive.Name = mo.Properties["Caption"].Value.ToString().Trim(); if (mo["SerialNumber"] != null) diskDrive.SerialNumber = mo.Properties["SerialNumber"].Value.ToString().Trim(); if (mo["Size"] != null) diskDrive.Size = (ulong)mo.Properties["Size"].Value / 1024 / 1024 / 1024; if (!diskDrive.Name.StartsWith("USBKey")) diskDrivelist.Add(diskDrive); } //获取网卡地址 ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection mocNetworkAdapter = mc.GetInstances(); NetworkAdapterlist = new List<NetworkAdapterInfo>(); foreach (ManagementObject mo in mocNetworkAdapter) { NetworkAdapterInfo networkAdapterInfo = new NetworkAdapterInfo(); if (mo["Caption"] != null) networkAdapterInfo.Name = mo["Caption"].ToString().Trim(); if (mo["MacAddress"] != null) networkAdapterInfo.MacAddress = mo["MacAddress"].ToString().Trim(); if (!networkAdapterInfo.Name.Contains("VMware") && !networkAdapterInfo.Name.Contains("Microsoft") && !networkAdapterInfo.Name.Contains("Virtual") && !networkAdapterInfo.Name.Contains("Miniport") && networkAdapterInfo.MacAddress.Contains(":") ) { NetworkAdapterlist.Add(networkAdapterInfo); } } //主板 ManagementClass cimobjectBaseBoard = new ManagementClass("WIN32_BaseBoard"); ManagementObjectCollection mocBaseBoard = cimobjectBaseBoard.GetInstances(); foreach (ManagementObject mo in mocBaseBoard) { if (mo["SerialNumber"] != null) baseBoard.SerialNumber = mo.Properties["SerialNumber"].Value.ToString().Trim(); if (mo["Name"] != null) baseBoard.Name = mo.Properties["Name"].Value.ToString().Trim(); if (mo["Manufacturer"] != null) baseBoard.Manufacturer = mo.Properties["Manufacturer"].Value.ToString().Trim(); if (mo["Product"] != null) baseBoard.Product = mo.Properties["Product"].Value.ToString().Trim(); } ManagementClass cimobjectBIOS = new ManagementClass("WIN32_BIOS"); ManagementObjectCollection mocBIOS = cimobjectBIOS.GetInstances(); foreach (ManagementObject mo in mocBIOS) { if (mo["SerialNumber"] != null) bios.SerialNumber = mo.Properties["SerialNumber"].Value.ToString().Trim(); if (mo["Name"] != null) bios.Name = mo.Properties["Name"].Value.ToString().Trim(); if (mo["Manufacturer"] != null) bios.Manufacturer = mo.Properties["Manufacturer"].Value.ToString().Trim(); if (mo["ReleaseDate"] != null) bios.ReleaseDate = mo.Properties["ReleaseDate"].Value.ToString().Trim(); } }
public MainFormPresenter(IMainForm form, ProcessorInfo processorInfo, PhysicalMemoryInfo physicalMemoryInfo, DiskDriveInfo diskDriveInfo) { _form = form; #region Get processor info _processorInfo = processorInfo; _form.ProcessorName = _processorInfo.Instance[0].Name; _temperatureLsit = new List <double>(); _form.MaxProcessorClockSpeed = _processorInfo.Instance[0].MaxClockSpeed; var processorsProperities = new Dictionary <string, string>(); processorsProperities.Add("AddressWidth", _processorInfo.Instance[0].AddressWidth); processorsProperities.Add("Architecture", _processorInfo.Instance[0].Architecture); processorsProperities.Add("Caption", _processorInfo.Instance[0].Caption); processorsProperities.Add("DataWidth", _processorInfo.Instance[0].DataWidth); processorsProperities.Add("Description", _processorInfo.Instance[0].Description); processorsProperities.Add("DeviceId", _processorInfo.Instance[0].DeviceId); processorsProperities.Add("Family", _processorInfo.Instance[0].Family); processorsProperities.Add("Manufactured", _processorInfo.Instance[0].Manufactured); processorsProperities.Add("Name", _processorInfo.Instance[0].Name); processorsProperities.Add("NumberOfCores", _processorInfo.Instance[0].NumberOfCores); processorsProperities.Add("NumberOfEnabledCore", _processorInfo.Instance[0].NumberOfEnabledCore); processorsProperities.Add("NumberOfLogicalProcessors", _processorInfo.Instance[0].NumberOfLogicalProcessors); processorsProperities.Add("PartNumber", _processorInfo.Instance[0].PartNumber); processorsProperities.Add("ProcessorId", _processorInfo.Instance[0].ProcessorId); processorsProperities.Add("SerialNumber", _processorInfo.Instance[0].SerialNumber); processorsProperities.Add("Status", _processorInfo.Instance[0].Status); processorsProperities.Add("ThreadCount", _processorInfo.Instance[0].ThreadCount); foreach (var processorProperity in processorsProperities) { var item = new ListViewItem(processorProperity.Key, 0); item.SubItems.Add(processorProperity.Value); _form.ProcessorProperitiesListView.Items.Add(item); } _calcProcessorTempThread = new Thread(new ThreadStart(ReloadProcessorTemp)); _calcProcessorSpeedThread = new Thread(new ThreadStart(ReloadProcessorSpeed)); _calcProcessorTempThread.Start(); _calcProcessorSpeedThread.Start(); #endregion #region Get physical memory info _physicalMemoryInfo = physicalMemoryInfo; var physicalMemoryDevices = new Dictionary <string, string> [_physicalMemoryInfo.Instance.Length]; for (int i = 0; i < _physicalMemoryInfo.Instance.Length; i++) { var physicalMemoryProperities = new Dictionary <string, string>(); physicalMemoryProperities.Add("BankLabel", _physicalMemoryInfo.Instance[i].BankLabel); physicalMemoryProperities.Add("Capacity", _physicalMemoryInfo.Instance[i].Capacity); physicalMemoryProperities.Add("Caption", _physicalMemoryInfo.Instance[i].Caption); physicalMemoryProperities.Add("ConfiguredClockSpeed", _physicalMemoryInfo.Instance[i].ConfiguredClockSpeed); physicalMemoryProperities.Add("ConfiguredVoltage", _physicalMemoryInfo.Instance[i].ConfiguredVoltage); physicalMemoryProperities.Add("DataWidth", _physicalMemoryInfo.Instance[i].DataWidth); physicalMemoryProperities.Add("Description", _physicalMemoryInfo.Instance[i].Description); physicalMemoryProperities.Add("DeviceLocator", _physicalMemoryInfo.Instance[i].DeviceLocator); physicalMemoryProperities.Add("Manufacturer", _physicalMemoryInfo.Instance[i].Manufacturer); physicalMemoryProperities.Add("Name", _physicalMemoryInfo.Instance[i].Name); physicalMemoryProperities.Add("PartNumber", _physicalMemoryInfo.Instance[i].PartNumber); physicalMemoryProperities.Add("PositionInRow", _physicalMemoryInfo.Instance[i].PositionInRow); physicalMemoryProperities.Add("Speed", _physicalMemoryInfo.Instance[i].Speed); physicalMemoryDevices[i] = physicalMemoryProperities; } foreach (var device in physicalMemoryDevices) { foreach (var physicalMemoryProperity in device) { var item = new ListViewItem(physicalMemoryProperity.Key, 0); item.SubItems.Add(physicalMemoryProperity.Value); _form.PhysicalMemoryProperitiesListView.Items.Add(item); } } #endregion #region Get disk drive info _diskDriveInfo = diskDriveInfo; var diskDriveDevices = new Dictionary <string, string> [_diskDriveInfo.Instance.Length]; for (int i = 0; i < _diskDriveInfo.Instance.Length; i++) { var diskDriveProperities = new Dictionary <string, string>(); diskDriveProperities.Add("BytesPerSector", _diskDriveInfo.Instance[i].BytesPerSector); diskDriveProperities.Add("Capabilities", _diskDriveInfo.Instance[i].Capabilities); diskDriveProperities.Add("CapabilityDescriptions", _diskDriveInfo.Instance[i].CapabilityDescriptions); diskDriveProperities.Add("Caption", _diskDriveInfo.Instance[i].Caption); diskDriveProperities.Add("Description", _diskDriveInfo.Instance[i].Description); diskDriveProperities.Add("DeviceId", _diskDriveInfo.Instance[i].DeviceId); diskDriveProperities.Add("InterfaceType", _diskDriveInfo.Instance[i].InterfaceType); diskDriveProperities.Add("Manufacturer", _diskDriveInfo.Instance[i].Manufacturer); diskDriveProperities.Add("Model", _diskDriveInfo.Instance[i].Model); diskDriveProperities.Add("Name", _diskDriveInfo.Instance[i].Name); diskDriveProperities.Add("Partitions", _diskDriveInfo.Instance[i].Partitions); diskDriveProperities.Add("PNPDeviceID", _diskDriveInfo.Instance[i].PNPDeviceID); diskDriveProperities.Add("SectorsPerTrack", _diskDriveInfo.Instance[i].SectorsPerTrack); diskDriveProperities.Add("SerialNumber", _diskDriveInfo.Instance[i].SerialNumber); diskDriveProperities.Add("Size", _diskDriveInfo.Instance[i].Size); diskDriveProperities.Add("Status", _diskDriveInfo.Instance[i].Status); diskDriveProperities.Add("SystemName", _diskDriveInfo.Instance[i].SystemName); diskDriveProperities.Add("TotalCylinders", _diskDriveInfo.Instance[i].TotalCylinders); diskDriveProperities.Add("TotalHeads", _diskDriveInfo.Instance[i].TotalHeads); diskDriveProperities.Add("TotalSectors", _diskDriveInfo.Instance[i].TotalSectors); diskDriveProperities.Add("TotalTracks", _diskDriveInfo.Instance[i].TotalTracks); diskDriveProperities.Add("TracksPerCylinder", _diskDriveInfo.Instance[i].TracksPerCylinder); diskDriveDevices[i] = diskDriveProperities; } foreach (var device in diskDriveDevices) { foreach (var diskDriveProperity in device) { var item = new ListViewItem(diskDriveProperity.Key, 0); item.SubItems.Add(diskDriveProperity.Value); _form.DiskDriveProperitiesListView.Items.Add(item); } } #endregion _form.ApplicationClose += _form_ApplicationClose; }