0

我正在编写一个基于 .NET 的应用程序,用于检查系统中一个或多个磁盘的健康状况。

我可以使用 ATAPI 的 WMI 接口来获取 SMART 数据,然后链接:http ://wutils.com/wmi/root/wmi/msstoragedriver_atapismartdata/

但我不知道如何执行 SMART 自检。有没有办法通过使用 C# 来做到这一点?

4

2 回答 2

0

感谢卢信,

作为您的向导,我已经成功了,但我只成功地执行了 Short Selft-test 和 Extended Selft-test。甚至我的硬盘也支持在离线模式下立即测试SMART Conveyance自检程序(值= 03h)。但它总是返回代码是 1 'Captive Mode Required'。你知道如何执行这个测试吗?

我遵循 ATA/ATAPI 注释集 ACS-3 规范 [表 127,http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf]以准确了解执行 SMART Selft-test 的输入参数

inParams["子命令"] = ?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
        * ********************************************************************/

为了知道我的硬盘可以支持离线模式下执行 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.
     * *******************************************************************/

谢谢你的帮助,

竹子

于 2017-08-27T08:52:49.917 回答
0

我试图做同样的事情,发现可以通过 WMI 开始测试。查看命名空间MSStorageDriver_FailurePredictFunction下的 WMI 类ROOT\WMI。该类有几种不同的方法可供您使用。其中之一是ExecuteSelfTest方法。看看我用 WMI Code Creator ( 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 更改为您的磁盘名称。我还发现"Subcommand"参数是决定你实际开始什么测试的因素。如果值是1您启动Short Self-test. 如果值是2您启动Extended Self-test.

作为输出参数,您可以['0', '1', '2']0代表'Successful Completion'1代表'Captive Mode Required'2代表时接收这三个值之一'Unsuccessful Completion'。来源(FailurePredictFunction

于 2017-08-22T08:02:29.303 回答