Answer the question
In order to leave comments, you need to log in
How to fix "ManagementException not handled" error in VS2012?
I use the code to determine the temperature of the processor
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.Management.Instrumentation;
namespace temperature
{
class Program
{
static void Main(string[] args)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData WHERE Active=True");
foreach (ManagementObject obj in searcher.Get())
{
byte[] vendorSpec = obj["VendorSpecific"] as byte[];
if (vendorSpec != null)
{
Console.WriteLine("Температура = " + vendorSpec[115]);
}
}
Console.ReadKey();
}
}
}
Answer the question
In order to leave comments, you need to log in
Not enough access rights. Run the resulting exe as an administrator, or run the entire Visual Studio as an administrator. I recommend testing all wmi requests with wbemtest or powershell cmdlet Get-WmiObject
class Program
{
static void Main(string[] args)
{
try{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData WHERE Active=True");
foreach (ManagementObject obj in searcher.Get())
{
byte[] vendorSpec = obj["VendorSpecific"] as byte[];
if (vendorSpec != null)
{
Console.WriteLine("Температура = " + vendorSpec[115]);
}
}
Console.ReadKey();
}
catch(Exception ex) {
ex.message - будет содержать текст сообщения об ошибке и его можно вывести через messagebox или хотя бы посмотреть в отладке
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question