Im trying to get hardware info from PC using ManagmentObjectSearcher (CPU, GPU etc).
Its pretty clear, that this class is included in System.Management (like is said in MSDN Site).
Could you tell me, how to get this object? I give a reference to this using statement.
The error that i get is:
CS0246 C# The type or namespace name could not be found (are you missing a using directive or an assembly reference?)
If it will help, my code:
using System.Management; //no error here
namespace KMM_HighPerformance.Models
{
class GetHardwareInfo
{
static public void GetCPU()
{
ManagmentObjectSearcher m = new ManagmentObjectSearcher(); //i get red line here
}
}
}
Thanks for any advices!
Change typo "ManagmentObjectSearcher" to "ManagementObjectSearcher" .
Try this if you want get processor ID:
using System.Management;
namespace KMM_HighPerformance.Models
{
class GetHardwareInfo
{
static public void GetCPU()
{
var mbs = new ManagementObjectSearcher("Select ProcessorID From Win32_processor");
var mbsList = mbs.Get();
foreach (ManagementObject mo in mbsList)
{
var cpuid = mo["ProcessorID"].ToString();
}
}
}
}
Under the project name right click on references - > Add reference
in the newly opened windows under assemblies search for System.Management
just tick System.Management one and press okay

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With