提问人:Abhijeet Kumar Jha 提问时间:10/31/2023 最后编辑:Ted LyngmoAbhijeet Kumar Jha 更新时间:10/31/2023 访问量:34
WMI 类异常“无效类”
WMI class exception "Invalid class"
问:
我正在尝试使用以下代码使用 WMI 或其他方式在 .NET 中获取 SMART 寄存器,这会导致以下数据,但我在所有代码中都收到“无效类”异常。
注册名称 当前值 最差值 阈值 数据(供应商) SMART 状态
enter code here
代码 1
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"SELECT *
FROM MSStorageDriver_ATAPISMARTData");
foreach (ManagementObject disk in searcher.Get())
{
// Retrieve SMART attributes
ushort[] rawValues = (ushort[])disk["VendorSpecific"];
// Extract specific SMART attributes
string registerName = Encoding.Default.GetString(rawValues, 2, 2);
ushort currentValue = rawValues[0]; // Current Value
ushort worstValue = rawValues[1]; // Worst Value
ushort thresholdValue = rawValues[3]; // Threshold Value
Console.WriteLine($"Register Name: {registerName}");
Console.WriteLine($"Current Value: {currentValue}");
Console.WriteLine($"Worst Value: {worstValue}");
Console.WriteLine($"Threshold Value: {thresholdValue}");
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
在此输入验证码 代码 2
try
{
var searcher = new ManagementObjectSearcher("Select * from
Win32_DiskDrive");
searcher.Scope = new ManagementScope(@"\root\wmi");
searcher.Query = new ObjectQuery("Select * from
MSStorageDriver_FailurePredictStatus");
foreach (ManagementObject drive in searcher.Get())
{
--
}
}
enter code here
代码 3
try
{
ManagementScope scope = new ManagementScope( "\\\\FullComputerName\\root\\cimv2");
scope.Connect();
ObjectQuery query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictData");
ManagementObjectSearcher searcher =new ManagementObjectSearcher(scope,query);
foreach (ManagementObject drive in searcher.Get())
{
--
}
}
答: 暂无答案
评论