我正在编写一个基于 .NET 的应用程序,用于检查系统中磁盘或多个磁盘的健康状况。
我可以使用 ATAPI 的 WMI 接口来获取 SMART 数据,后跟链接:http://wutils.com/wmi/root/wmi/msstoragedriver_atapismartdata/
但我不知道如何执行智能自检。有什么方法可以使用 C# 来做到这一点吗?
我试图做同样的事情,发现可以通过 WMI 开始测试。查看ROOTWMI
命名空间下的 WMI 类MSStorageDriver_FailurePredictFunction
。该类有几种不同的方法可以使用。其中之一是ExecuteSelfTest
方法。 看看我用WMI Code Creator(WMICodeCreator(创建的这个例子
try
{
ManagementObject classInstance =
new ManagementObject("root\WMI",
"MSStorageDriver_FailurePredictFunction.InstanceName='SCSIDisk&Ven_Hitachi&Prod_HDS721010CLA6324&7d4adf0&0&010000_0'",
null);
// Obtain in-parameters for the method
ManagementBaseObject inParams =
classInstance.GetMethodParameters("ExecuteSelfTest");
// Add the input parameters.
inParams["Subcommand"] = 1;
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
classInstance.InvokeMethod("ExecuteSelfTest", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnCode: " + outParams["ReturnCode"]);
}
catch(ManagementException err)
{
MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
}
您必须将上述代码中的实例名称更改为磁盘名称。我还发现,"Subcommand"
参数是决定您实际开始什么测试的因素。 如果值1
则启动Short Self-test
。 如果值2
则启动Extended Self-test
。
作为输出参数,您可以接收这三个值之一['0', '1', '2']
0
代表'Successful Completion'
,1
代表'Captive Mode Required'
,2
代表'Unsuccessful Completion'
。源(故障预测函数(
谢谢 LuXxn,
我已经成功地作为您的指南,但我只能成功执行简短的自我测试和扩展的自我测试。甚至我的硬盘也支持在离线模式下立即测试SMART Transportance自检程序(值= 03h(。但它始终返回代码为 1"需要捕获模式"。您知道如何执行此测试吗?
我遵循了 ATA/ATAPI 注释集 ACS-3 规范 [表 127,http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf] 来准确了解执行 SMART 自检的输入参数
inParams["Subcommand"] = ?value;
/* *********************************************************************
* Table 127 — SMART EXECUTE OFF-LINE IMMEDIATE Subcommands/Draft ATA/ATAPI Comment Set ACS-3
* http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf
* Value Description of subcommand to be processed
* 00h Execute SMART off-line routine immediately in off-line mode
* 01h Execute SMART Short self-test routine immediately in off-line mode
* 02h Execute SMART Extended self-test routine immediately in off-line mode
* 03h Execute SMART Conveyance self-test routine immediately in off-line mode
* 04h Execute SMART Selective self-test routine immediately in off-line mode
* 05h-3Fh Reserved
* 40h-7Eh Vendor specific
* 7Fh Abort off-line mode self-test routine
* 80h Reserved
* 81h Execute SMART Short self-test routine immediately in captive mode
* 82h Execute SMART Extended self-test routine immediately in captive mode
* 83h Execute SMART Conveyance self-test routine immediately in captive mode
* 84h Execute SMART Selective self-test routine immediately in captive mode
* 85h-8Fh Reserved
* 90h-FFh Vendor specific
* ********************************************************************/
为了知道我的硬盘可以支持在离线模式下执行智能传送自检,我发送了 S.M.A.R.T 命令来获取离线收集功能的值,然后返回值0x73并遵循 ATA/ATAPI 注释集 ACS-3 规范 [表 133,http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf]
/**********************************************************************
* Table 133 — Offline Data Collection Capabilities
* Bit Description
* 7 Reserved
* 6 SELECTIVE SELF-TEST IMPLEMENTED bit – If this bit is cleared to zero, the device does not implement the
* Selective self-test routine. If this bit is set to one, the device implements the Selective self-test routine.
* 5 CONVEYANCE SELF-TEST IMPLEMENTED bit – If this bit is cleared to zero, the device does not implement the
* Conveyance self-test routines. If this bit is set to one, the device implements the Conveyance self-test
* routines.
* 4 SELF-TEST IMPLEMENTED bit – If this bit is cleared to zero, the device does not implement the Short and
* Extended self-test routines. If this bit is set to one, the device implements the Short and Extended
* self-test routines.
* 3 OFF-LINE READ SCANNING IMPLEMENTED bit – If this bit is cleared to zero, the device does not support
* off-line read scanning. If this bit is set to one, the device supports off-line read scanning.
* 2 ABORT/RESTART OFF-LINE BY HOST bit – If this bit is set to one, then the device shall abort all off-line data
* collection activity initiated by a SMART EXECUTE OFF-LINE IMMEDIATE command upon receipt of a
* new command within 2 seconds of receiving the new command. If this bit is cleared to zero, the device
* shall suspend off-line data collection activity after an interrupting command and resume off-line data
* collection activity after some vendor-specified event.
* 1 Vendor specific.
* 0 EXECUTE OFF-LINE IMMEDIATE IMPLEMENTED bit – If this bit is set to one, then the SMART EXECUTE
* OFF-LINE IMMEDIATE command is implemented by this device. If this bit is cleared to zero, then the
* SMART EXECUTE OFF-LINE IMMEDIATE command is not implemented by this device.
* *******************************************************************/
感谢您的帮助,
竹