[英]How I can get the installed RAM and CPU details c# .Net Core?
I need a installed total RAM in GB and also the CPU details as well.我需要以 GB 为单位的已安装总 RAM 以及 CPU 详细信息。 I see lot post related to this.
我看到很多与此相关的帖子。 But, I'm not sure which is suitable for me.
但是,我不确定哪个适合我。 And, also I tried with couple of examples but its not provided the expected result.
而且,我也尝试了几个例子,但它没有提供预期的结果。
For example, I need like below,例如,我需要如下所示,
RAM Size = 16 GB RAM 大小 = 16 GB
CPU = Intel(R) Core(TM) i5 3.20 GHz 2 Cores CPU = Intel(R) Core(TM) i5 3.20 GHz 2 核
Note: I'm not expect the available or used memory.注意:我不期望可用或使用的 memory。
Update:更新:
To get the RAM details I used the below code要获取 RAM 详细信息,我使用了以下代码
string Query = "SELECT MaxCapacity FROM Win32_PhysicalMemoryArray";
ManagementObjectSearcher searcher123 = new ManagementObjectSearcher(Query);
foreach (ManagementObject WniPART in searcher123.Get())
{
UInt32 SizeinKB = Convert.ToUInt32(WniPART.Properties["MaxCapacity"].Value);
UInt32 SizeinMB = SizeinKB / 1024;
UInt32 SizeinGB = SizeinKB / (1024 * 1024);
Console.WriteLine("Size in KB: {0}, Size in MB: {1}, Size in GB: {2}", SizeinKB, SizeinMB, SizeinGB);
}
But, This gave me wrong Data(Infact, it give 32 GB instead of 16GB)但是,这给了我错误的数据(事实上,它给了 32 GB 而不是 16GB)
Looks like you're using the wrong class.看起来您使用了错误的 class。 Try the
Win32_PhysicalMemory
class and the Capacity
property尝试
Win32_PhysicalMemory
class 和Capacity
属性
var query = "SELECT Capacity FROM Win32_PhysicalMemory";
var searcher = new ManagementObjectSearcher(query);
foreach (var WniPART in searcher.Get())
{
var capacity = Convert.ToUInt64(WniPART.Properties["Capacity"].Value);
var capacityKB = capacity / 1024;
var capacityMB = capacityKB / 1024;
var capacityGB = capacityMB / 1024;
System.Console.WriteLine("Size in KB: {0}, Size in MB: {1}, Size in GB: {2}", capacityKB, capacityMB, capacityGB);
}
The MaxCapacity
property in the Win32_PhysicalMemoryArray
class will give you the maximum amount of RAM installable on your machine, not the amount of memory that is actually installed. MaxCapacity
中的Win32_PhysicalMemoryArray
属性将为您提供机器上可安装的最大 RAM 量,而不是实际安装的 memory 量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.