我正在編寫一個基於.NET的應用程序,用於檢查系統中磁盤或多個磁盤的健康情況。如何執行SMART自檢
我可以使用WMI接口ATAPI到在SMART數據,然後鏈接獲得:http://wutils.com/wmi/root/wmi/msstoragedriver_atapismartdata/
但我不知道如何執行SMART自檢。有沒有辦法通過使用C#來完成它?
我正在編寫一個基於.NET的應用程序,用於檢查系統中磁盤或多個磁盤的健康情況。如何執行SMART自檢
我可以使用WMI接口ATAPI到在SMART數據,然後鏈接獲得:http://wutils.com/wmi/root/wmi/msstoragedriver_atapismartdata/
但我不知道如何執行SMART自檢。有沒有辦法通過使用C#來完成它?
我試圖做同樣的事情,發現可以通過WMI啓動測試。查看ROOT\WMI
名稱空間下的WMI類MSStorageDriver_FailurePredictFunction
。該類有幾種不同的方法可以使用。其中之一是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);
}
您必須更改實例名在上面的代碼到你的diskname創建。我還發現,"Subcommand"
參數是決定你實際開始測試的因素。 如果值爲1
,則開始Short Self-test
。 如果值爲2
,則開始Extended Self-test
。
正如你可以接收這三個值['0', '1', '2']
的一個輸出參數 而0
代表'Successful Completion'
,1
代表'Captive Mode Required'
和2
代表'Unsuccessful Completion'
。源(FailurePredictFunction)
感謝LuXxn,
我已經爲你的嚮導成功,但我只許成功執行短Selft測試和擴展Selft測試。即使我的硬盤也支持立即以離線模式(值= 03h)測試SMART Conveyance自檢程序。但它總是返回代碼是1'Captive Mode Required'。你知道如何執行這個測試嗎?
我跟着ATA/ATAPI註釋設置ACS-3規範[表127,http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf]確切地知道輸入參數EXCUTE SMART Selft測試
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.
* *******************************************************************/
感謝您的幫助,
竹
感謝LuXxn,它是如此之大!。我已經通過這種方式來執行SMART Self-Test。 –
我只能設法執行短自我測試和擴展自我測試。我無法通過其他測試來完成。你如何「跟蹤」你的測試?你讀過任何日誌或東西,看看它是否成功? – Luca