- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我如何阅读 HDD 的 SMART 寄存器 在 .NET 中使用 WMI 或其他方式,这会导致具有以下数据:
最佳答案
经过一些工作,我已经将代码放在一起,使用 C#/WMI 返回有关 HDD 的所有相关 SMART 信息的综合报告。
/*
Copyright (c) 2013, Llewellyn Kruger
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Management;
public class HDD
{
public int Index { get; set; }
public bool IsOK { get; set; }
public string Model { get; set; }
public string Type { get; set; }
public string Serial { get; set; }
public Dictionary<int, Smart> Attributes = new Dictionary<int, Smart>() {
{0x00, new Smart("Invalid")},
{0x01, new Smart("Raw read error rate")},
{0x02, new Smart("Throughput performance")},
{0x03, new Smart("Spinup time")},
{0x04, new Smart("Start/Stop count")},
{0x05, new Smart("Reallocated sector count")},
{0x06, new Smart("Read channel margin")},
{0x07, new Smart("Seek error rate")},
{0x08, new Smart("Seek timer performance")},
{0x09, new Smart("Power-on hours count")},
{0x0A, new Smart("Spinup retry count")},
{0x0B, new Smart("Calibration retry count")},
{0x0C, new Smart("Power cycle count")},
{0x0D, new Smart("Soft read error rate")},
{0xB8, new Smart("End-to-End error")},
{0xBE, new Smart("Airflow Temperature")},
{0xBF, new Smart("G-sense error rate")},
{0xC0, new Smart("Power-off retract count")},
{0xC1, new Smart("Load/Unload cycle count")},
{0xC2, new Smart("HDD temperature")},
{0xC3, new Smart("Hardware ECC recovered")},
{0xC4, new Smart("Reallocation count")},
{0xC5, new Smart("Current pending sector count")},
{0xC6, new Smart("Offline scan uncorrectable count")},
{0xC7, new Smart("UDMA CRC error rate")},
{0xC8, new Smart("Write error rate")},
{0xC9, new Smart("Soft read error rate")},
{0xCA, new Smart("Data Address Mark errors")},
{0xCB, new Smart("Run out cancel")},
{0xCC, new Smart("Soft ECC correction")},
{0xCD, new Smart("Thermal asperity rate (TAR)")},
{0xCE, new Smart("Flying height")},
{0xCF, new Smart("Spin high current")},
{0xD0, new Smart("Spin buzz")},
{0xD1, new Smart("Offline seek performance")},
{0xDC, new Smart("Disk shift")},
{0xDD, new Smart("G-sense error rate")},
{0xDE, new Smart("Loaded hours")},
{0xDF, new Smart("Load/unload retry count")},
{0xE0, new Smart("Load friction")},
{0xE1, new Smart("Load/Unload cycle count")},
{0xE2, new Smart("Load-in time")},
{0xE3, new Smart("Torque amplification count")},
{0xE4, new Smart("Power-off retract count")},
{0xE6, new Smart("GMR head amplitude")},
{0xE7, new Smart("Temperature")},
{0xF0, new Smart("Head flying hours")},
{0xFA, new Smart("Read error retry rate")},
/* slot in any new codes you find in here */
};
}
public class Smart
{
public bool HasData
{
get
{
if (Current == 0 && Worst == 0 && Threshold == 0 && Data == 0)
return false;
return true;
}
}
public string Attribute { get; set; }
public int Current { get; set; }
public int Worst { get; set; }
public int Threshold { get; set; }
public int Data { get; set; }
public bool IsOK{ get; set; }
public Smart()
{
}
public Smart(string attributeName)
{
this.Attribute = attributeName;
}
}
/// <summary>
/// Tested against Crystal Disk Info 5.3.1 and HD Tune Pro 3.5 on 15 Feb 2013.
/// Findings; I do not trust the individual smart register "OK" status reported back frm the drives.
/// I have tested faulty drives and they return an OK status on nearly all applications except HD Tune.
/// After further research I see HD Tune is checking specific attribute values against their thresholds
/// and and making a determination of their own (which is good) for whether the disk is in good condition or not.
/// I recommend whoever uses this code to do the same. For example -->
/// "Reallocated sector count" - the general threshold is 36, but even if 1 sector is reallocated I want to know about it and it should be flagged.
/// </summary>
public class Program
{
public static void Main()
{
try
{
// retrieve list of drives on computer (this will return both HDD's and CDROM's and Virtual CDROM's)
var dicDrives = new Dictionary<int, HDD>();
var wdSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
// extract model and interface information
int iDriveIndex = 0;
foreach (ManagementObject drive in wdSearcher.Get())
{
var hdd = new HDD();
hdd.Model = drive["Model"].ToString().Trim();
hdd.Type = drive["InterfaceType"].ToString().Trim();
dicDrives.Add(iDriveIndex, hdd);
iDriveIndex++;
}
var pmsearcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
// retrieve hdd serial number
iDriveIndex = 0;
foreach (ManagementObject drive in pmsearcher.Get())
{
// because all physical media will be returned we need to exit
// after the hard drives serial info is extracted
if (iDriveIndex >= dicDrives.Count)
break;
dicDrives[iDriveIndex].Serial = drive["SerialNumber"] == null ? "None" : drive["SerialNumber"].ToString().Trim();
iDriveIndex++;
}
// get wmi access to hdd
var searcher = new ManagementObjectSearcher("Select * from Win32_DiskDrive");
searcher.Scope = new ManagementScope(@"\root\wmi");
// check if SMART reports the drive is failing
searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictStatus");
iDriveIndex = 0;
foreach (ManagementObject drive in searcher.Get())
{
dicDrives[iDriveIndex].IsOK = (bool)drive.Properties["PredictFailure"].Value == false;
iDriveIndex++;
}
// retrive attribute flags, value worste and vendor data information
searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictData");
iDriveIndex = 0;
foreach (ManagementObject data in searcher.Get())
{
Byte[] bytes = (Byte[])data.Properties["VendorSpecific"].Value;
for (int i = 0; i < 30; ++i)
{
try
{
int id = bytes[i*12 + 2];
int flags = bytes[i * 12 + 4]; // least significant status byte, +3 most significant byte, but not used so ignored.
//bool advisory = (flags & 0x1) == 0x0;
bool failureImminent = (flags & 0x1) == 0x1;
//bool onlineDataCollection = (flags & 0x2) == 0x2;
int value = bytes[i*12 + 5];
int worst = bytes[i*12 + 6];
int vendordata = BitConverter.ToInt32(bytes, i*12 + 7);
if (id == 0) continue;
var attr = dicDrives[iDriveIndex].Attributes[id];
attr.Current = value;
attr.Worst = worst;
attr.Data = vendordata;
attr.IsOK = failureImminent == false;
}
catch
{
// given key does not exist in attribute collection (attribute not in the dictionary of attributes)
}
}
iDriveIndex++;
}
// retreive threshold values foreach attribute
searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictThresholds");
iDriveIndex = 0;
foreach (ManagementObject data in searcher.Get())
{
Byte[] bytes = (Byte[])data.Properties["VendorSpecific"].Value;
for (int i = 0; i < 30; ++i)
{
try
{
int id = bytes[i*12 + 2];
int thresh = bytes[i*12 + 3];
if (id == 0) continue;
var attr = dicDrives[iDriveIndex].Attributes[id];
attr.Threshold = thresh;
}
catch
{
// given key does not exist in attribute collection (attribute not in the dictionary of attributes)
}
}
iDriveIndex++;
}
// print
foreach (var drive in dicDrives)
{
Console.WriteLine("-----------------------------------------------------");
Console.WriteLine(" DRIVE ({0}): " + drive.Value.Serial + " - " + drive.Value.Model + " - " + drive.Value.Type, ((drive.Value.IsOK) ? "OK" : "BAD"));
Console.WriteLine("-----------------------------------------------------");
Console.WriteLine("");
Console.WriteLine("ID Current Worst Threshold Data Status");
foreach (var attr in drive.Value.Attributes)
{
if (attr.Value.HasData)
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t " + attr.Value.Data + " " + ((attr.Value.IsOK) ? "OK" : ""), attr.Value.Attribute, attr.Value.Current, attr.Value.Worst, attr.Value.Threshold);
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
}
Console.ReadLine();
}
catch (ManagementException e)
{
Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
}
}
}
var drives = Simplified.IO.Smart.GetDrives(); // Static Method
关于c# - 如何在 C# .NET 中读取 HDD S.M.A.R.T 寄存器并获取该寄存器的所有关联值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14688589/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!