我正在编写一个基于.NET的应用程序,用于检查系统中磁盘或更多磁盘的健康状况。
我可以使用ATAPI的WMI界面获取SMART数据,然后链接:http://wutils.com/wmi/root/wmi/msstoragedriver_atapismartdata/
但我不知道如何执行SMART Self-Test。有什么方法可以通过使用C#来实现吗?
答案 0 :(得分:0)
我试图做同样的事情,发现可以通过WMI开始测试。查看MSStorageDriver_FailurePredictFunction
命名空间下的WMI类ROOT\WMI
。该类有几种不同的方法可供使用。其中之一是ExecuteSelfTest
方法。
请看我使用WMI代码创建器(WMICodeCreator)
try
{
ManagementObject classInstance =
new ManagementObject("root\\WMI",
"MSStorageDriver_FailurePredictFunction.InstanceName='SCSI\Disk&Ven_Hitachi&Prod_HDS721010CLA632\4&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);
}
您必须将上面代码中的InstanceName更改为您的diskname。我还发现,"Subcommand"
参数是决定实际开始测试的因素。
如果值为1
,则启动Short Self-test
。
如果值为2
,则启动Extended Self-test
。
作为输出参数,您可以收到这三个值中的一个['0', '1', '2']
虽然0
代表'Successful Completion'
,1
代表'Captive Mode Required'
而2
代表'Unsuccessful Completion'
。源(FailurePredictFunction)
答案 1 :(得分:0)
感谢LuXxn,
我已经成为您的导游,但我只能成功执行Short Selft-test和Extended Selft-test。甚至我的硬盘也支持在离线模式下立即测试SMART Conveyance自检例程(值= 03h)。但它总是返回代码是1'需要的俘获模式'。你知道怎么执行这个测试吗?
我遵循ATA / ATAPI注释设置ACS-3规范[表127,http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf]以确切知道输入参数以执行SMART Selft-test
inParams ["子命令"] =?值;
/* *********************************************************************
* 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
* ********************************************************************/
要知道我的硬盘可以支持在离线模式下执行SMART传输自检,我发送了SMART命令以获取OfflineCollectCapability的值,然后返回值为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.
* *******************************************************************/
感谢您的帮助,
竹