Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7707217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:18:14+00:00 2026-06-01T00:18:14+00:00

In an attempt to develop a hard disk analytic tool, I’m trying to get

  • 0

In an attempt to develop a hard disk analytic tool, I’m trying to get the value of Load/Unload cycle count from my hard disk’s S.M.A.R.T data, I’m wondering if anyone knows how to do this.
What I’m trying:

  1. I’m searching the WMI MSStorageDriver_ATAPISmartData class data where attribute number 193 is what i need (the attribute representing load/unload cycle count)
  2. The data I’m getting looks like

enter image description here

I think I’m close, the data in red is the same as what Everest Home edition is showing when i run it, ideally i would want the last part which is (attribute called data)

enter image description here

Method for collecting this data:

static void doStuff()
{
    try
    {

        byte TEMPERATURE_ATTRIBUTE = 193;

        ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"\root\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData");
        //loop through all the hard disks
        foreach (ManagementObject queryObj in searcher.Get())
        {
            byte[] arrVendorSpecific = (byte[])queryObj.GetPropertyValue("VendorSpecific");

            int tempIndex = Array.IndexOf(arrVendorSpecific, TEMPERATURE_ATTRIBUTE);
            Console.WriteLine("HDD TEMP: " + arrVendorSpecific[tempIndex + 5].ToString());

            foreach (byte dat in arrVendorSpecific)
            {
                Console.Write(dat.ToString() + " ");
            }
        }

    }
    catch (Exception err) { Console.WriteLine(err.Message); }
}

P.S. this method works for collecting the HDD’s temperature (that’s what the Console.WriteLine("HDD TEMP: " + arrVendorSpecific[tempIndex + 5].ToString()); line is all about but I’m not sure why its tempIndex+5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:18:15+00:00Added an answer on June 1, 2026 at 12:18 am

    The code which you are using is not correct, because you are using a secuencial search (Array.IndexOf) to find the S.M.A.R.T Attribute ID (you can have false positives because that value can match with another in the array), the ID of these attibutes has an fixed position inside of an documented structure (SMART Attribute Overview).

    SMART Attribute Table

    Offset  Length  Description
            (bytes) 
    0         2      SMART structure version (this is vendor-specific)
    2         12     Attribute entry 1
    2+(12)    12     Attribute entry 2
    . . .
    2+(12*29) 12     Attribute entry 30
    

    Entry in the Attribute Table

    enter image description here

    from here you can write a code to search the location of each attribute and get the values which you are looking for

    using System;
    using System.Collections.Generic;
    using System.Management;
    using System.Text;
    using System.Runtime.InteropServices;
    
    namespace GetWMI_Info
    {
        class Program
        {
    
            [StructLayout(LayoutKind.Sequential)]
            public struct Attribute
            {
                public byte AttributeID;
                public ushort Flags;
                public byte Value;
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
                public byte[] VendorData;
            }
    
            static void Main(string[] args)
            {
                try
                {
                    Attribute AtributeInfo;
                    ManagementScope Scope = new ManagementScope(String.Format("\\\\{0}\\root\\WMI", "localhost"), null);
                    Scope.Connect();
                    ObjectQuery Query = new ObjectQuery("SELECT VendorSpecific FROM MSStorageDriver_ATAPISmartData");
                    ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query);
                    byte LoadCycleCount = 0xC1;
                    int Delta  = 12;
                    foreach (ManagementObject WmiObject in Searcher.Get())
                    {
                        byte[] VendorSpecific = (byte[])WmiObject["VendorSpecific"];
                        for (int offset = 2; offset < VendorSpecific.Length; )
                        {
                            if (VendorSpecific[offset] == LoadCycleCount)
                            {
    
                                IntPtr buffer = IntPtr.Zero;
                                try
                                {
                                    buffer = Marshal.AllocHGlobal(Delta);
                                    Marshal.Copy(VendorSpecific, offset, buffer, Delta);
                                    AtributeInfo = (Attribute)Marshal.PtrToStructure(buffer, typeof(Attribute));
                                    Console.WriteLine("AttributeID {0}", AtributeInfo.AttributeID);
                                    Console.WriteLine("Flags {0}", AtributeInfo.Flags);
                                    Console.WriteLine("Value {0}", AtributeInfo.Value);
                                    Console.WriteLine("Value {0}", BitConverter.ToString(AtributeInfo.VendorData));
                                }
                                finally
                                {
                                    if (buffer != IntPtr.Zero)
                                    {
                                        Marshal.FreeHGlobal(buffer);
                                    }
                                }                                                
                            }
                            offset += Delta;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(String.Format("Exception {0} Trace {1}",e.Message,e.StackTrace));
                }
                Console.WriteLine("Press Enter to exit");
                Console.Read();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an attempt to learn C#, I am trying to develop Picasa Like Application
I am trying very hard to develop a much deeper understanding of programming as
I attempt to use webservice return POCO class generated from entity data model as
In an attempt to wrap some unmanaged code in a managed .dll I'm trying
When I attempt to debug a simple program with gdb on cygwin I get
I'm trying to develop a generic command processor. I would like to create command
In SQL Server Management Studio, if I attempt to restore a database from a
In attempt to learn Hadoop, I am practicing unsolved programming questions from the book
I've been trying to develop a linq query that returns the ItemNumber column of
When I attempt to run my blackberry app in the simulator I get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.