Exemplo n.º 1
0
        private void ReadMemoryModulesInfo()
        {
            using (var searcher = new ManagementObjectSearcher("select * from Win32_PhysicalMemory"))
            {
                try
                {
                    foreach (var queryObject in searcher.Get().Cast <ManagementObject>())
                    {
                        ulong  capacity   = 0UL;
                        uint   clockSpeed = 0U;
                        string partNumber = "N/A";
                        object temp;

                        temp = WMI.TryGetProperty(queryObject, "Capacity");
                        if (temp != null)
                        {
                            capacity = (ulong)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "ConfiguredClockSpeed");
                        if (temp != null)
                        {
                            clockSpeed = (uint)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "partNumber");
                        if (temp != null)
                        {
                            partNumber = (string)temp;
                        }

                        modules.Add(new MemoryModule(partNumber, capacity, clockSpeed));
                        comboBoxPartNumber.Items.Add($"{partNumber}");
                        comboBoxPartNumber.SelectedIndex = 0;
                    }

                    if (modules.Count > 0)
                    {
                        var totalCapacity = 0UL;

                        foreach (var module in modules)
                        {
                            totalCapacity += module.Capacity;
                        }

                        if (modules.FirstOrDefault().ClockSpeed != 0)
                        {
                            MEMCFG.Frequency = modules.FirstOrDefault().ClockSpeed;
                        }

                        if (totalCapacity != 0)
                        {
                            MEMCFG.TotalCapacity = $"{totalCapacity / 1024 / (1024 * 1024)}GB";
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Failed to get installed memory parameters. Corresponding fields will be empty.",
                                    "Warning",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
        }
Exemplo n.º 2
0
        private void ReadMemoryModulesInfo()
        {
            using (var searcher = new ManagementObjectSearcher("select * from Win32_PhysicalMemory"))
            {
                try
                {
                    foreach (var queryObject in searcher.Get().Cast <ManagementObject>())
                    {
                        ulong  capacity      = 0UL;
                        uint   clockSpeed    = 0U;
                        string partNumber    = "N/A";
                        string bankLabel     = "";
                        string manufacturer  = "";
                        string deviceLocator = "";
                        object temp;

                        temp = WMI.TryGetProperty(queryObject, "Capacity");
                        if (temp != null)
                        {
                            capacity = (ulong)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "ConfiguredClockSpeed");
                        if (temp != null)
                        {
                            clockSpeed = (uint)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "partNumber");
                        if (temp != null)
                        {
                            partNumber = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "BankLabel");
                        if (temp != null)
                        {
                            bankLabel = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "Manufacturer");
                        if (temp != null)
                        {
                            manufacturer = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "DeviceLocator");
                        if (temp != null)
                        {
                            deviceLocator = (string)temp;
                        }

                        modules.Add(new MemoryModule(partNumber, bankLabel, manufacturer, deviceLocator, capacity, clockSpeed));

                        string bl = bankLabel.Length > 0 ? new string(bankLabel.Where(char.IsDigit).ToArray()) : "";
                        //string dl = deviceLocator.Length > 0 ? new string(deviceLocator.Where(char.IsDigit).ToArray()) : "";

                        comboBoxPartNumber.Items.Add($"#{bl}: {partNumber}");

                        comboBoxPartNumber.SelectedIndex = 0;
                    }

                    if (modules.Count > 0)
                    {
                        var totalCapacity = 0UL;

                        foreach (var module in modules)
                        {
                            totalCapacity += module.Capacity;
                        }

                        if (modules.FirstOrDefault().ClockSpeed != 0)
                        {
                            MEMCFG.Frequency = modules.FirstOrDefault().ClockSpeed;
                        }

                        if (totalCapacity != 0)
                        {
                            MEMCFG.TotalCapacity = $"{totalCapacity / 1024 / (1024 * 1024)}GB";
                        }
                    }
                }
                catch
                {
                    AdonisUI.Controls.MessageBox.Show("Failed to get installed memory parameters. Corresponding fields will be empty.",
                                                      "Warning",
                                                      AdonisUI.Controls.MessageBoxButton.OK,
                                                      AdonisUI.Controls.MessageBoxImage.Warning);
                }
            }
        }
Exemplo n.º 3
0
        private void ReadMemoryModulesInfo()
        {
            using (var searcher = new ManagementObjectSearcher("select * from Win32_PhysicalMemory"))
            {
                bool connected = false;
                try
                {
                    WMI.Connect(@"root\cimv2");

                    connected = true;

                    foreach (var queryObject in searcher.Get().Cast <ManagementObject>())
                    {
                        var capacity      = 0UL;
                        var clockSpeed    = 0U;
                        var partNumber    = "N/A";
                        var bankLabel     = "";
                        var manufacturer  = "";
                        var deviceLocator = "";

                        var temp = WMI.TryGetProperty(queryObject, "Capacity");
                        if (temp != null)
                        {
                            capacity = (ulong)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "ConfiguredClockSpeed");
                        if (temp != null)
                        {
                            clockSpeed = (uint)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "partNumber");
                        if (temp != null)
                        {
                            partNumber = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "BankLabel");
                        if (temp != null)
                        {
                            bankLabel = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "Manufacturer");
                        if (temp != null)
                        {
                            manufacturer = (string)temp;
                        }

                        temp = WMI.TryGetProperty(queryObject, "DeviceLocator");
                        if (temp != null)
                        {
                            deviceLocator = (string)temp;
                        }

                        modules.Add(new MemoryModule(partNumber.Trim(), bankLabel.Trim(), manufacturer.Trim(),
                                                     deviceLocator, capacity, clockSpeed));

                        //string bl = bankLabel.Length > 0 ? new string(bankLabel.Where(char.IsDigit).ToArray()) : "";
                        //string dl = deviceLocator.Length > 0 ? new string(deviceLocator.Where(char.IsDigit).ToArray()) : "";

                        //comboBoxPartNumber.Items.Add($"#{bl}: {partNumber}");
                        //comboBoxPartNumber.SelectedIndex = 0;
                    }
                }
                catch (Exception ex)
                {
                    var title = connected ? @"Failed to get installed memory parameters." : $@"{ex.Message}";
                    MessageBox.Show(
                        title,
                        "Warning",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning);
                }
            }

            if (modules.Count > 0)
            {
                ReadChannelsInfo();

                var totalCapacity = 0UL;

                foreach (var module in modules)
                {
                    var rank = module.DualRank ? "DR" : "SR";
                    totalCapacity += module.Capacity;
                    comboBoxPartNumber.Items.Add(
                        $"{module.Slot}: {module.PartNumber} ({module.Capacity / 1024 / (1024 * 1024)}GB, {rank})");
                }

                if (modules[0].ClockSpeed != 0)
                {
                    MEMCFG.Frequency = modules[0].ClockSpeed;
                }

                if (totalCapacity != 0)
                {
                    MEMCFG.TotalCapacity = $"{totalCapacity / 1024 / (1024 * 1024)}GB";
                }

                comboBoxPartNumber.SelectedIndex     = 0;
                comboBoxPartNumber.SelectionChanged += ComboBoxPartNumber_SelectionChanged;
            }
        }