Reputation:
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!
Upvotes: 2
Views: 1395
Reputation: 3113
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();
}
}
}
}
Upvotes: 5
Reputation: 431
Add a reference to the DLL System.Management
. your code should work.
and also change ManagmentObjectSearcher
to ManagementObjectSearcher
Upvotes: 0
Reputation: 1925
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
Upvotes: 3