简体   繁体   中英

Get Manufacturer name for my RAM (WMI didn't get this information)

I need to get the full information about RAM modules. I tried to get it by using an WMI:

ManagementObjectSearcher searcher12 =
    new ManagementObjectSearcher("root\\CIMV2",
    "SELECT * FROM Win32_PhysicalMemory");

            Console.WriteLine("------------- Win32_PhysicalMemory instance --------");
            foreach (ManagementObject queryObj in searcher12.Get())
            {
                Console.WriteLine("BankLabel: {0} ; Capacity: {1} Gb; Speed: {2}; Manufacturer: {3}; Serial Number: {4}", queryObj["BankLabel"],
                                  Math.Round(System.Convert.ToDouble(queryObj["Capacity"]) / 1024 / 1024 / 1024, 2),
                                   queryObj["Speed"], queryObj["Manufacturer"], queryObj["Name"]);
            }

but it didn't help me, it simply doesn't have this information. How can I get this information?

The above code works on Windows 10. I copied and pasted the above code into a console application.

I had to add a reference to System.Management.

When I run it I get the following output:

------------- Win32_PhysicalMemory instance --------
BankLabel: BANK 0 ; Capacity: 4 Gb; Speed: 1333; Manufacturer: Hynix; Serial Number: Physical Memory
BankLabel: BANK 1 ; Capacity: 4 Gb; Speed: 1333; Manufacturer: Unknown; Serial Number: Physical Memory

You can use the below code to find the Manufacturer and Part Number of Physical Memory of your system:

using System;
using System.Management;

namespace GetRAM
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementScope oMs = new ManagementScope();
            ObjectQuery oQuery = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
            ManagementObjectCollection oCollection = oSearcher.Get();

            foreach (ManagementObject obj in oCollection)
            {
                Console.WriteLine($"Manufacturer: {obj["Manufacturer"]} | Part Number: {obj["PartNumber"]}");
            }
        }
    }
}

You can also use the below command in Command Prompt to get the details:

wmic MEMORYCHIP get Manufacturer, PartNumber

Results:

在此处输入图片说明

You can use this code as below :

using System.Management;

ObjectQuery wql = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wql);
ManagementObjectCollection results = searcher.Get();

foreach (ManagementObject result in results)
{
    Console.WriteLine("Total Visible Memory: {0} KB", result["TotalVisibleMemorySize"]);
    Console.WriteLine("Free Physical Memory: {0} KB", result["FreePhysicalMemory"]);
    Console.WriteLine("Total Virtual Memory: {0} KB", result["TotalVirtualMemorySize"]);
    Console.WriteLine("Free Virtual Memory: {0} KB", result["FreeVirtualMemory"]);
}

and the output is :

Total Visible Memory: 16617056 KB
Free Physical Memory: 2465396 KB
Total Virtual Memory: 35511496 KB
Free Virtual Memory: 4005632 KB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM